Hello,
I trying to check if the user-inputted string is a valid install destination, then check if it exists, and create it if not. My problem is with validating that the destination string is formatted properly.
I am currently using IO.Directory.Exists( String path )
and works fine except when the user did not format the string properly. That method will return false, but I won't be able to create the folder afterwards.
Googling suggested I use regular expressions to check if the format is proper. I have 0 experience with regular expressions, and am wondering if that will work. Here's what I found:
Regex r = new Regex( @"^(([a-zA-Z]\:)|(\\))(\\{1}|((\\{1})[^\\]([^/:*?<>""|]*))+)$" );
return r.IsMatch( path );
Would this, in combination with Directory.Exists()
, give me a good enough method to check if the path is valid and it exists? I know this will vary with OS and other factors, but the program is targeted for Windows users only.
Of course, if there is a simpler solution please do tell!
Thanks!