I asked a question recently on searching directories in C#.
Program Logic
- List all the directories in a string, or multiple strings.
- Try to copy the file out using the string.
- If it fails, proceed to the next string,
- If it succeeds in finding the file:
- copy
- skip to next entry in text file
End Result
If it finds it on the 4th string it doesn’t try the next 15 strings.
Code Snippet
if (checkBox2.Checked)
{
string[] file_names = File.ReadAllLines(@"c:\dact.txt");
string path1 = @"I:\pa\test\";
string path2 = @"I:\pa\test2\";
string path3 = @"I:\pa\test3\";
string path4 = @"I:\pa\test4\";
string full = (string.Concat(path1, file_names, ".txt"));
foreach (string file_name in file_names)
if (System.IO.File.Exists(full))
{
foreach (string file in file_names)
System.IO.File.Copy(file,
@"C:\" +
textBox1.Text +
@"\\OC\" +
file_name + ".txt");
}
}
The code above does not contain the ability to write out failed files, I'm not sure how to do that.
This is what I want:
1. Read all lines of a text file
2. Try to copy files from a specific directory
3. Whatever files fails, it writes out to a text file the failed files
4. it reads all the new "failed list", then trys the 2nd path in my list.
5. repeats process to third path - 19th path.