rye004
asked on
Pattern searching for file extensions in c#
I have to go through a set of files and see if the extension meets a specific pattern.
Below is the pattern of files that I am currently looking for:
"*.pst *.ost *.e0* *.l0* *.ghs *.gho *.7z *.7z.* *.exp *.ilk *.res *.trg *.tlh *.idb *.pdb *.pch *.opt *.lib *.cab *.mov *.psp *.bmp *.chi *.chm *.com *.dll *.exe *.gif *.png *.hlp *.ivi *.ivt *.ix *.msi *.nls *.obj *.ocx *.rmi *.sys *.tif *.tmp *.ttf *.vbx *.wav *.wpg DRVSPACE.* *.iso *.pdb *.mpeg *.mpg *.ram *.rm *.ai *.aif *.aiff *.bin *.hqx *.snd *.mpe *.wmv *.wma *.xfd *.db *.m4v"
I know Directory.GetFiles has a pattern option. However it will only let me specify one at a time. I would like to go through each file individually, then check the extension then do any needed reporting on it.
Any input would be greatly appreciated.
Below is the pattern of files that I am currently looking for:
"*.pst *.ost *.e0* *.l0* *.ghs *.gho *.7z *.7z.* *.exp *.ilk *.res *.trg *.tlh *.idb *.pdb *.pch *.opt *.lib *.cab *.mov *.psp *.bmp *.chi *.chm *.com *.dll *.exe *.gif *.png *.hlp *.ivi *.ivt *.ix *.msi *.nls *.obj *.ocx *.rmi *.sys *.tif *.tmp *.ttf *.vbx *.wav *.wpg DRVSPACE.* *.iso *.pdb *.mpeg *.mpg *.ram *.rm *.ai *.aif *.aiff *.bin *.hqx *.snd *.mpe *.wmv *.wma *.xfd *.db *.m4v"
I know Directory.GetFiles has a pattern option. However it will only let me specify one at a time. I would like to go through each file individually, then check the extension then do any needed reporting on it.
Any input would be greatly appreciated.
ASKER
julianH,
Thank you for your posting, it is greatly appreciated. For the most part I got the code working. It iterates through the array with no issues. My only problem is the regular expression does not seem to work. Would you mind giving me additional input on the regular expression?
Many thanks!
Thank you for your posting, it is greatly appreciated. For the most part I got the code working. It iterates through the array with no issues. My only problem is the regular expression does not seem to work. Would you mind giving me additional input on the regular expression?
Many thanks!
ASKER
I think I just figured it out. I tried the following and it worked:
{ @"^.*\.dll", @"^.*\.exe", @"^.*\.cab", @"^.*\.htm" };
{ @"^.*\.dll", @"^.*\.exe", @"^.*\.cab", @"^.*\.htm" };
(apologies for not posting earlier - did not pick up your earlier post)
That is odd - the code I posted worked fine with the regex I used there.
Your regex is using match 0 or more (*) as opposed to 1 or more + and is including the ^ to match from the beginning.
I will look at the code I posted again and post back.
That is odd - the code I posted worked fine with the regex I used there.
Your regex is using match 0 or more (*) as opposed to 1 or more + and is including the ^ to match from the beginning.
I will look at the code I posted again and post back.
ASKER
Thanks! Your time is greatly appreciated!
ASKER
curious, did have a sec to look at this?
Many thanks!
Many thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much for this. I understand getting locked up on a project – I have been in the same situation.
So far, this seems to work well. I will continue playing with it.
Thanks again!
So far, this seems to work well. I will continue playing with it.
Thanks again!
You are welcome - thanks for the points
Open in new window