- Home /
Copying files from one directory to the other
I have been tinkering with Unity's editor and managed to create a tool that helps me copy files from one directory to the other. It works fine, but for some reason when I want it to copy my files to the desktop it just doesn't let me. It tells me that it fails to copy files.
using UnityEditor;
using System.Diagnostics;
public class UnityEditorClass {
[MenuItem("Tools/DLL With Postprocess")]
public static void BuildGame()
{
// Copy a file from the project folder to the build folder, alongside the built game.
FileUtil.CopyFileOrDirectory("C:/Projects/SchoolProjects/GSP290/MyFirstGame/vector2.dll", "Desktop/vector2.dlll");
FileUtil.CopyFileOrDirectory("C:/Projects/SchoolProjects/GSP290/MyFirstGame/matrixHelper.dll", "Desktop/matrixHelper.dll");
}
}
Can anyone help me figure out what I am doing wrong and how can I fix this? Thank you in advance!
Answer by GameVortex · Jan 14, 2014 at 07:28 PM
Desktop is not a root location. The path to your desktop is something like: C:/Users/UserName/Desktop.
Ye, I tried that but it doesn't work. Isn't there a way around it?
You have also included an extra 'l' at the end in the first function. It should not really stop anything, it just renames the file ins$$anonymous$$d. But check all your paths and names for typos. And if it still fails, maybe it does not have access. Try running Unity as ad$$anonymous$$istrator.
To get the desktop folder path you can use this. $$anonymous$$eep in $$anonymous$$d to use forward slashes in the path. Also FileUtil is a Unity class, so there might be some additional special formatting of the path since it also allows project paths. Depending on your operating system you (the Unity editor) don't have enough privileges to access the desktop folder.
Try using System.IO
classes and see if you get any exception. Usually if an action fails you should get an excpetion telling you what went wrong.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130436im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Distribute terrain in zones 3 Answers
Working with Unity Editor 1 Answer
Multiple Cars not working 1 Answer