I'm trying to solve a problem with an app I've compiled to speed up my work. The idea is to organise my folder structure automatically (copying files from source to target folders), based on the file extension using a WinForm app. The problem is that I've recently started coding with C# and I can't find a way to deal with the nested duplicated files in my folder structure.
Example of the tree structure:
| Analysis.xls
| Handoff request.msg
| Reference documentation.doc
|
\---Trados package
+---DE
| Translation text.sdlxliff
|
+---EN
| Translation text.sdlxliff
|
+---FR
| Translation text.sdlxliff
|
+---SV
| Translation text.sdlxliff
|
\---TM
+---DE
| Ref TM.sdltm
|
+---FR
| Ref TM.sdltm
|
\---SV
Ref TM.sdltm
I've managed to compile a solution (based on some good suggestions here) to help me out with the unique files, however I'm not able to handle the duplicated ones that are nested in the language folders.
{
var sourcePath = @"C:\Users\Home\Desktop\source";
var targetPath = @"C:\Users\Home\Desktop\target";
var extensions = new[] { ".sdlxliff", ".mqxliff", ".sdltm", ".tmx" };
var files = (from file in System.IO.Directory.EnumerateFiles(sourcePath, "*", SearchOption.AllDirectories)
where extensions.Contains(System.IO.Path.GetExtension(file), StringComparer.InvariantCultureIgnoreCase)
select new
{
Source = file,
Destination = System.IO.Path.Combine(targetPath, System.IO.Path.GetFileName(file))
});
{
foreach (var file in files)
File.Copy(file.Source, file.Destination);
MessageBox.Show("Done", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
The expected result would be to have the duplicated files copied with their parent folder in the target folder (i.e. If I'm trying to copy Translation text.sdlxliff from the source directory "C:\Users\Home\Desktop\source\Trados package\DE" then the file should be added in the following target folder "C:\Users\Home\Desktop\target\Trados package\DE". The same is expected to happen with the TM folder and all the nested files in it.
Thanks for the suggestions.