I have a question regarding file comparison or string matching... I have a directory full of files that I would like to copy to a "working" folder else move to a "corrupted" folder.
All of the file names have the following structure:
{Username}_{Date}_{Section Type}.txt
JoeSoap_28032006_SectionOne.txt and JoeSoap_28032006_SectionThere.txt or PietS_13052006_SectionOne.txt and PietSnot_13052006_SectionThere.txt
In theory there should always be two files, "SectionOne.txt" and "SectionThere.txt"
Each filename is unique, i.e. there will always only be one of eah file. Now... I would like to return all the files ending with "Section1.txt" and then find all the "Section2.txt" files associated with the "Section1.txt" file.
Section1 FileName | Section2 FileName | Action JoeSoap_28032006_SectionOne.txt | JoeSoap_28032006_SectionThere.txt | Move to "Working" folder. PietSnot_13052006_SectionOne.txt | | Move to "Corrupted" folder. | PietSnot_13052006_SectionThere.txt | Move to "Corrupted" folder. etc.....
Could anybody please point me in the right direction on this. It's pretty urgent I haven't been able to figure it out.
Here is how I would go about it. Note that this presumes that all the files in the folder are named along the guidelines you presented. If this may not be the case, then you will need to add code to skip files that do not:
One more note is that the example data you gave:
Section1 FileName | Section2 FileName | Action JoeSoap_28032006_SectionOne.txt | JoeSoap_28032006_SectionThere.txt | Move to "Working" folder. PietSnot_13052006_SectionOne.txt | | Move to "Corrupted" folder. | PietSnot_13052006_SectionThere.txt | Move to "Corrupted" folder.
Does not look the way I think you meant it to. In your data, both sections are present for both users so I think they should all be moved to working.