topaz-dev’s

ああああああ

UnityでFile操作する

ファイルの作成をする

ファイルを既に存在する場合新しく作ってしまうのでファイルが存在するかを確認する必要がある。

// targetPathには拡張子(.txt)なども含める。
string targetPath = Application.dataPath + "/" + path + "/" + fileName;

if (File.Exists(targetPath))
{
    Debug.LogWarning($"{targetPath} は存在します");
    // ファイルが存在する場合新しく空のファイルを生成してしまう。
    // File.Create(targetPath);
}
else
{
    Debug.LogWarning($"{targetPath} は存在しません");
     File.Create(targetPath);
}

// データベースを更新する
AssetDatabase.Refresh();