Hi there,
Thanks for reading my question. I’m not really a coder, but have been asked to develop a demo. I am trying to build a system whereby the user loads in images to Unity to be displayed at runtime. The user specifies a path from a GUI input field, and then presses a button which should load the files from the specified folder into a folder in the resources folder. The code references the source folder variable from another script. Things are fine until the files are supposed to move, when I get the following error
IOException: Win32 IO returned ERROR_ALREADY_EXISTS. Path:
I have read elsewhere that this is because it is trying to overwrite files in the folder, but the folder is empty, and I have written a function which checks at the start of the runtime and should delete any files.
If anybody would be as kind to point in me the right direction, I am pulling my hair out a bit.
void Start () {
DirectoryInfo text = new DirectoryInfo(Application.dataPath + "/Resources/Text");
DirectoryInfo images = new DirectoryInfo(Application.dataPath + "/Resources/Images");
textPath = text.FullName;
imagesPath = images.FullName;
Debug.Log(textPath);
Debug.Log(imagesPath);
DontDestroyOnLoad (this);
checkFolders ();
}
void checkFolders () {
if (Directory.Exists(imagesPath) && Directory.Exists(textPath))
{
Debug.Log ("Images Exist & Text Exists");
string [] iFiles = Directory.GetFiles(imagesPath);
foreach (string iFilename in iFiles)
File.Delete(iFilename);
string [] tFiles = Directory.GetFiles(textPath);
foreach (string tFilename in tFiles)
File.Delete(tFilename);
return;
}
Directory.CreateDirectory (Application.dataPath + "/Resources/Text");
Directory.CreateDirectory (Application.dataPath + "/Resources/Images");
Debug.Log("Creating Images Folder");
}
void LoadResources () {
//run through source folder
string imageSourcePath = UserSessionDefs.imagePath;
Debug.Log (imageSourcePath);
string [] imagesFiles = Directory.GetFiles(UserSessionDefs.imagePath);
foreach (string image in imagesFiles)
{Debug.Log (image);
File.Move (imageSourcePath, imagesPath);}
Thanks in advance.