Reputation: 85
I have a fairly unique situation. Did a lot of searching and most of what I'm seeing terminates at finding a particular file, using wildcards ("*.txt") as an example. What I need to do is move a file between paths, the first one having a changing subdirectory. I am downloading a .zip, extracting it, and moving a file who's name never changes. Its parent directory does change in name, based on a datestamp.
//original extracted folder
string path = @"C:\IP-Test_20140715\File.csv";
//where to move
string path2 = @"C:\File.csv";
File.csv will never change, yet IP-Test_20140715 will change based on the date (whatever the extracted folder is called), everything after the underscore will be different going forward.
If not possible to have wildcards in directories, is it possible to force the name of the extracted directory in c# using ZipFile.ExtractToDirectory
?
Upvotes: 0
Views: 2072
Reputation: 476503
Use:
Directory.EnumerateFiles (@"C:\IP-Test_20140715", "*.txt")
to enumerate over the different files.
Thus:
foreach(var subdir in Directory.EnumerateDirectories (@"C:\", "IP-Test_*")) {
foreach(var file in Directory.EnumerateFiles (subdir, "*.cvs")) {
File.Move(file,Path.Combine(@"C:\",Path.GetFileName(file)));
}
}
On the other hand, I don't see why you want to use C# for this? A simple bash
script could do the trick way easier...
Upvotes: 1