-
We have the FileUtil class
that lets you do move, copy, delete
operations over files or directories. -
We have the AssetDatabase
class that lets you create a new
folder. -
Is there any class that lets you check if a folder exists? Or should I use C# Directory.Exists?
You can now do:
AssetDatabase.IsValidFolder(string path);
My guess is functions like AssetDatabase.CreateFolder were implemented because adding a file to a Unity project is different than creating a normal file. There is probably some overhead involved (like registering it with the project or saving its state).
In contrast, checking whether a file exists is the same in all environments (whether you're writing a Unity application or not). My theory is this is why there is no need to create a "Unity version" of the function that checks if a file exists.
I had the same question a week ago, and that's how I've rationalized what I've found (or not found) in the documentation.
Edit - Just came acros this in the docs:
File Operations using the AssetDatabase
Since Unity keeps metadata about asset files, you should never create, move or delete them using the filesystem.
Instead, you can use AssetDatabase.Contains, AssetDatabase.CreateAsset, AssetDatabase.CreateFolder, AssetDatabase.RenameAsset, AssetDatabase.CopyAsset, AssetDatabase.MoveAsset, AssetDatabase.MoveAssetToTrash and AssetDatabase.DeleteAsset.