I’m trying to move an already existing file to the desktop. here’s the code. basically it doesn’t move the file when i play
public static string GetDirectory(string tag)
{
switch (tag)
{
case "%Desktop%":
return Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}
return null;
}
public void Movefile(){
AssetDatabase.CopyAsset("Assets/Music/Background.ogg","%Desktop%");
}
As indicated in the documentation, All paths are relative to the project folder
You need to use the functions from the System.IO
namespace instead.
public static string GetDirectory(string tag)
{
switch (tag)
{
case "%Desktop%":
return Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}
return null;
}
public static string GetAssetPath(string projectPath)
{
projectPath = projectPath.Substring("Assets".Length);
return Application.dataPath + projectPath;
}
public void Movefile()
{
System.IO.File.Move(
GetAssetPath("Assets/Music/Background.ogg"),
GetDirectory("%Desktop%") + "/Background.ogg"
);
}