list subdirectories with specific names
-
Hi, I have to get list of subdirectoris in parent folder ("A_ParentDir") which have names in format "vX.XX" where X is numeric. Example : I have folder A_ParentDir which contains list of directories as below : v3.20 v4.56 v8.1 v5.60a v6.00v6.00 so I should have only : v3.20 v4.56 I tried as below but I have also the last one in result v3.20 v4.56 v6.00v6.00 // this shouldn't be
string strreg = @"v\d{1}\.{1}\d{2}$";
arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
.Where(path => Regex.IsMatch(path, strreg))
.ToList();thank for help
-
Hi, I have to get list of subdirectoris in parent folder ("A_ParentDir") which have names in format "vX.XX" where X is numeric. Example : I have folder A_ParentDir which contains list of directories as below : v3.20 v4.56 v8.1 v5.60a v6.00v6.00 so I should have only : v3.20 v4.56 I tried as below but I have also the last one in result v3.20 v4.56 v6.00v6.00 // this shouldn't be
string strreg = @"v\d{1}\.{1}\d{2}$";
arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
.Where(path => Regex.IsMatch(path, strreg))
.ToList();thank for help
You need to add a "start of string" indicator to your regex:
string strreg = @"^v\d{1}\.{1}\d{2}$";
But a simpler to read version would be:
string strreg = @"^v\d\.\d\d$";
If you are going to use Regexes, then I'd suggest you get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
You need to add a "start of string" indicator to your regex:
string strreg = @"^v\d{1}\.{1}\d{2}$";
But a simpler to read version would be:
string strreg = @"^v\d\.\d\d$";
If you are going to use Regexes, then I'd suggest you get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Hi, I have to get list of subdirectoris in parent folder ("A_ParentDir") which have names in format "vX.XX" where X is numeric. Example : I have folder A_ParentDir which contains list of directories as below : v3.20 v4.56 v8.1 v5.60a v6.00v6.00 so I should have only : v3.20 v4.56 I tried as below but I have also the last one in result v3.20 v4.56 v6.00v6.00 // this shouldn't be
string strreg = @"v\d{1}\.{1}\d{2}$";
arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
.Where(path => Regex.IsMatch(path, strreg))
.ToList();thank for help
Ignore the previous answer! I forgot the folder path was there... :-O Best way is to do this:
string strreg = @"^v\d\.\d\d{2}$";
arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
.Where(path => Regex.IsMatch(Path.GetFileName(path), strreg))
.ToList()Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Nope - see my other reply! :-O
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...