Moving the multiple files from one to another location
-
hi! I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory. I had already done one file but i couldn't move multiple xml files. please do my favour. thanx & regards
-
hi! I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory. I had already done one file but i couldn't move multiple xml files. please do my favour. thanx & regards
Here is how i would do it:
foreach (string f in Directory.GetFiles(@"C:\\MyFolder")) { if (f.EndsWith(".xml")) { string currentf = f.Substring(f.LastIndexOf('\\\\') + 1); File.Move(f, @"C:\\MyFolder\\MyXmlFolder\\" + currentf); } }
It iterates through every file in MyFolder and if it's an xml then move it to MyXmlFolder.
-
Here is how i would do it:
foreach (string f in Directory.GetFiles(@"C:\\MyFolder")) { if (f.EndsWith(".xml")) { string currentf = f.Substring(f.LastIndexOf('\\\\') + 1); File.Move(f, @"C:\\MyFolder\\MyXmlFolder\\" + currentf); } }
It iterates through every file in MyFolder and if it's an xml then move it to MyXmlFolder.
-
hi! I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory. I had already done one file but i couldn't move multiple xml files. please do my favour. thanx & regards
you may want to read up on the System.IO.Path[^] class, which offers methods to deal with file paths. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Here is how i would do it:
foreach (string f in Directory.GetFiles(@"C:\\MyFolder")) { if (f.EndsWith(".xml")) { string currentf = f.Substring(f.LastIndexOf('\\\\') + 1); File.Move(f, @"C:\\MyFolder\\MyXmlFolder\\" + currentf); } }
It iterates through every file in MyFolder and if it's an xml then move it to MyXmlFolder.