Im building for standalone. Im trying to copy a folder in my assetts to another folder in the c drive.
when i use Directory.Move(path,path) i get an error like this:
UnauthorizedAccessException: Access to the path is denied.
System.IO.Directory.Move (System.String sourceDirName, System.String destDirName) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/Directory.cs:403)
installer.Update () (at Assets/installer.js:35)
ive also tryed FileUtil.CopyFileOrDirectory (“path”, “path”)
it works just fine in the editor but when building, it produces a compiler error on that line only when i build saying FileUtil is an unknown identifier.
i am very fimiliar with creating individual directorys and files. and im sure i could manually write a code too loop through all of them and write them one at a time but i was hopeing someone had an easier answer to my problem or any ideas what i might be doing wrong in my first two attempts.
Thanks!
Best way I know of is this.
I’ve ran into lots of copy permission issues in the past and usually it comes down to the destination folders permission access.
You probably already tried this, but if System.IO can’t do it, Unity does have its own Serializing methods, but you’d again… have to iterate the files
Directly from MSDN How to: Copy, Delete, and Move Files and Folders (C# Programming Guide)
// Simple synchronous file copy operations with no user interface.
// To run this sample, first create the following directories and files:
// C:\Users\Public\TestFolder
// C:\Users\Public\TestFolder est.txt
// C:\Users\Public\TestFolder\SubDir est.txt
public class SimpleFileCopy
{
static void Main()
{
string fileName = "test.txt";
string sourcePath = @"C:\Users\Public\TestFolder";
string targetPath = @"C:\Users\Public\TestFolder\SubDir";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
// To copy a file to another location and
// overwrite the destination file if it already exists.
System.IO.File.Copy(sourceFile, destFile, true);
// To copy all the files in one directory to another directory.
// Get the files in the source folder. (To recursively iterate through
// all subfolders under the current directory, see
// "How to: Iterate Through a Directory Tree.")
// Note: Check for target path was performed previously
// in this code example.
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}
else
{
Console.WriteLine("Source path does not exist!");
}
// Keep console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
I also had unconsistent results with Directory.Move, got rid of it and used a classic Copy/Delete instead. I put the copy code on SO.