Given a directory tree, with root folder name is “rootuploaded”, I need to combine files in this tree into some groups, using rules below:
- Files in different subfolders cannot be grouped.
- Files in a group may have same or different extension.
- Each group must have minimum 2 files, maximum 5 files.
Grouping files based on 6 naming conventions (with top-down priority):
- FileName.ext, FileName_anything.ext, FileName_anythingelse.ext, ...
- FileName.ext, FileName-anything.ext, FileName-anythingelse.ext, ...
- FileName_1.ext, FileName_2.ext, ..., FileName_N.ext (maybe not continuous)
- FileName-1.ext, FileName-2.ext, ..., FileName-N.ext (maybe not continuous)
- FileName 1.ext, FileName 2.ext, ..., FileName N.ext (maybe not continuous)
- FileName1.ext, FileName2.ext, ..., FileNameN.ext (maybe not continuous)
Here is a simple example of program input and output:
Input is a directory tree look like this:
- rootuploaded\samplefolder\1232_2342.jpg
- rootuploaded\samplefolder\1232_234234_1.jpg
- rootuploaded\samplefolder\1232_234234_2.bmp
- rootuploaded\file-5.txt
- rootuploaded\file-67.txt
- rootuploaded\file-a.txt
- rootuploaded\file1.txt
- rootuploaded\file2.txt
- rootuploaded\file5.txt
- rootuploaded\filea.txt
- rootuploaded\file_sample.txt
- rootuploaded\file_sample_a.txt
Output:
Group 1
rootuploaded\samplefolder\1232_234234_1.jpg
rootuploaded\samplefolder\1232_234234_2.bmp
Group 2
rootuploaded\file1.txt
rootuploaded\file2.txt
rootuploaded\file5.txt
Group 3
rootuploaded\file-5.txt
rootuploaded\file-67.txt
Group 4
rootuploaded\file_sample.txt
rootuploaded\file_sample_a.txt
Cannot grouped
rootuploaded\samplefolder\1232_2342.jpg
rootuploaded\file-a.txt
rootuploaded\filea.txt