Friday, 9 August 2013

Check if file name exists

Check if file name exists

I'm using this powershell code to check if a file starting with 4 specific
chars exist in a specific path or not
$myPath = "c:\myFolder\";
$myFileBegin = "abc_";
test-path "$myPath$myFileBegin*";
It works and it's simple, but now I'm trying to do the same thing with C#.
I don't report all the code but basically I'm getting all files from the
folder with Directory.GetFiles and looping over those files and testing
with Regex.IsMatch.
Is this the correct way or is there a faster one like in powershell?

No comments:

Post a Comment