Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving files and folders

Status
Not open for further replies.

robertfah

Programmer
Mar 20, 2006
380
US
I've got a directory on ym web server that has files and folders (files within those folders too) in it. I'd like a way to go through this "root" folder and move all the files and folders in there to another location. Any ideas? I'm guessing I'd have to use the File.IO but not too sure how.
 
 
Ok...let me try to explain this again. I know how to copy folders and files from one location to another. The problem I am facing is I have 1 folder on my server that I need to move all the contents (not the actual folder, just the contents) to another location. The problem is the contents of this folder change daily; Day 1 there could be 4 folders (each containing files) and 10 files, the next day there could be 2 folders and 30 files, etc. So I can't hard code my folders and do a simple Directory.Move or File.Move either. I somehow need to get a list of all the objects in this 1 folder, then go through each one and say is it a file or folder, and do the appropriate method for each.

Does that make any more sense?
 
ok, here's how I got around it:

Code:
DirectoryInfo di = new DirectoryInfo(sESMPath);
DirectoryInfo[] dii = di.GetDirectories();

foreach (DirectoryInfo d in dii)
{
   if(!Directory.Exists(sFilesToZip + d.Name))
      Directory.CreateDirectory(sFilesToZip + d.Name);

   FileInfo[]fi = d.GetFiles();
   foreach (FileInfo f in fi)
       File.Copy(f.FullName, sFilesToZip + d.Name + @"\" + f.Name, true);
}

//Copy the files from the Customer Folder.
FileInfo[] files = di.GetFiles();
foreach(FileInfo file in files)
   File.Copy(file.FullName, sFilesToZip + file.Name, true);

just replace the variables that I have for paths and this will work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top