>Hello All, can anyone tell me why this RegEx is not working ?, basically I'm scanning directories looking for files with a .ogg extension, and renaming them with a .flac, ( yes it's my music collection :-) ) and thought this code would do the trick
>
>>//Code snippet.
>// Assume dir is a DirectoryInfo object.
>
>FileInfo[] filesInDir = dir.GetFiles();
>
>Regex rx = new Regex(".ogg/i");
>
>foreach ( FileInfo file in filesInDir )
>{
> MatchCollection theMatches = rx.Matches(file.FullName);
>
> if (theMatches.Count > 0)
> Console.WriteLine("Found a jpeg: {0}", theMatches[0].Value);
>}
>
>
>
>I know there are several hundred ogg files but this code doesn't find any, the other method would be to check file.Extension but I'm curious to know why this is failingLooking for file.Extension would make more sense to me (and be faster).
I am not an expert on RegEx but IIRC the dot in front of ogg is looking for any character, not necessarily a dot. I do not know what the
/i
stands for. If you are looking for end of string that would be
ogg$
or
ogg\z
.
If you wanted to look for the dot as a literal it would be
\.ogg$