Reputation: 63
I want to copy a resource file to another folder.
System.IO.File.Copy(@"Resources\empty.jpg", destFile);
Thought this might be as easy as that. But it throws me an error like: "Part of the path Resources\empty.jpg could not be found.
Any help here?
Upvotes: 0
Views: 1418
Reputation: 116
You need to know the file/folder in relation to where you currently are. As Francis said in the comment above, by default in VS you will be in the debug folder. If Resources is off the root of C:, you need to get yourself to the root of C: First somehow, either by referencing C: directly, or by using ..\ to work your way up, parent folder by parent folder.
If it is a sub-directory from where you are at, what you show above does work correctly when the file exists. I tried it myself, which means you are not likely referencing a path that exists within your project\bin\debug path.
If it is a folder off the project, then you need to get up to the project folder itself first, i.e. "..\..\Resources\empty.jog"
.
Upvotes: 1
Reputation: 2107
The answer is here https://msdn.microsoft.com/en-us/library/cc148994.aspx . Looks like you need a drive letter in front of your source folder name and possibly target folder name.
string fileName = "test237.txt";
string sourcePath = @"C:\temp";
string targetPath = @"C:\temp2";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
Upvotes: 0