I’ve got an xml configuration file with the following file formats:
<FILE FILEFORMAT="|PREFIX|DATETIME|-|STRING|NUMBER|_|DATETIME2|-|TIME|SUFFIX|" />
<FILE FILEFORMAT="|PREFIX|NUMBER|_|DATETIME|-|TIME|SUFFIX|" />
<FILE FILEFORMAT="|DATETIME|_|PREFIX|_|STRING|_|DATETIME2|-|TIME|SUFFIX|" />
<FILE FILEFORMAT="|PREFIX|_|STRING|_|STRING2|_|DATETIME|_|DATETIME2|-|TIME|SUFFIX|"/>
where prefix is only alphabet, datetime/datetime2 is just numbers, not the actual datetime type(I will convert that into datetime later on), string is another alphabet, number is 0 to 9 numbers, time is digits also, suffix is the format of the file like .xml or .txt.
Examples of actual files:
`SUXX20111101-BATCH2240_20111113-091322.txt` `TOBEME826908_20111113-091413.txt` `2011-12-01_MYSELF_ANDI_20111208-121517.txt` `WELL_MAYBENOT_TRUE_092011_20111215-022931.txt`
What I have to accomplish is to check weather the file name is according to specified format or not, there are multiple clients with different formats, I don’t know how to go and solve this puzzle, any help is greatly appreciated. basically the idea is not to touch the programming side if more files come in the future, adding their info to config file should suffice.
I’m not sure of what exactly you need, however if it’s a way to describe your filename pattern, you should simply use Regular Expression.
Then you just have to loop among all formats.
Here is a sample of how to do the search (assuming you have loaded your xml formats in formats, your searching directory in dir)
For more information on regexp : Regular expression on MSDN