- Home /
Add files to folder
Hey guys,
Sorry about the obscure title, but I have been trying to figure this out for so long, that I think my brain is melting... Anyway...
Basically, I want to take all the files in folder A and move them to C, which is inside B. Let me try to explain this a little better. I want to take all the files that are in the folder "tempPath", and move them to "folderA". This would be easy enough, but folderA already exists and it has stuff in it that I don't want to delete. And, for the life of me, I can't figure out how to do this!
tempPath is located at:
static string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "tempPath";
folderA is located at:
static public string folderA = "/Users/" + Environment.UserName + "/Documents/HardFiles/folderA";
I really appreciate any help you can give me! ∆ Gibson
Answer by syclamoth · Jan 25, 2012 at 10:57 PM
Easy enough-
using System.IO;
// inside the function:
foreach(string file in Directory.GetFiles(tempPath))
{
string fName = file.Substring(tempPath.Length + 1);
File.Move(file, Path.Combine(folderA, fName));
}
That should do it! Make sure that you don't have any files of the same name in the destination directory.
So, do you want it to overwrite those files? Or do you want it to skip them?
Yes, I get that, but the error you are reporting occurs when you are trying to move a file to a location where a file with the same name exists- what do you want to do in that situation?
Ok then. Have you tried a $$anonymous$$imal case? Just test it with two string literals and see if that works. I can't quite see what's going on here yet.
I'm not sure if that'd be useful... It's often difficult to read and comprehend long programs without having written them yourself. I can try, if you like.
I was just going to post the function, not the full code
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
File.Move wont work , error. IOException: Win32 IO returned ERROR_ALREADY_EXISTS. Path: 1 Answer
Distribute terrain in zones 3 Answers
Will System.IO.File work on Macs 2 Answers
How Do I Find Path of a File? 1 Answer