I am writing a Windows service which poll on a specific folder.
The directory contains various files, and each file derives from a previous split operation:
Input folder:
- FILE_A_PART_1_OF_2.txt
- FILE_A_PART_2_OF_2.txt
- FILE_B_PART_1_OF_3.txt
- FILE_B_PART_2_OF_3.txt
- FILE_C_PART_2_OF_3.txt
- FILE_C_PART_3_OF_3.txt
- FILE_D_PART_1_OF_3.txt
- FILE_D_PART_3_OF_3.txt
- FILE_E_PART_1_OF_1.txt
The Services should be able to merge only the complete files:
Output Folder (after the merge operation):
- FILE_A.txt
- FILE_E.txt
Input Folder (after the merge operation)
- FILE_B_PART_1_OF_3.txt
- FILE_B_PART_2_OF_3.txt
- FILE_C_PART_2_OF_3.txt
- FILE_C_PART_3_OF_3.txt
- FILE_D_PART_1_OF_3.txt
- FILE_D_PART_3_OF_3.txt
Unfortunately i have to use framework 2.0. Language is C#. I know it’s not a complicated algorithm but somehow i can’t put myself into the right direction.
The merge operation is not important, so it can be expressed like:
Merge(string[] filesPart) or Merge(List<string> filesPart).
Thank you in advance.
First, grab all files, with
Directory.GetFiles()And then your main tool would be the
Dictionary<>class.I think I would use something like:
This would allow you to scan the list of files, parse the name and store it.
After the scan, only process a file when
Total == Parts.Count.As long as the
ninPART_n_OF_mremains < 10 you can simply sort theList<string> Parts.When it can become >= 10 you’ll need something like
SortedList<int, string> Parts