in reply to How to validate windows path

No regexp needed, simply check if $dir exists with the -e test.
if -e $dir print "valid path";
etc...

Replies are listed 'Best First'.
Re^2: How to validate windows path
by Anonymous Monk on Mar 13, 2012 at 10:23 UTC

    $ perl -le " print -e qq'C:/\0blah'
    1

    $ perl -MPath::Class -le " print file(qq'C:/\0blah')->resolve "
    C:\

Re^2: How to validate windows path
by roteme (Acolyte) on Mar 13, 2012 at 11:48 UTC
    No, my program get path from the user as parameter and need to check if the path is valid - if yes then create the folder.

      Define 'valid'. One approach would be to 'try it and see'. Attempt the create, if that succeeds, check to verify the directory exists1. In this case, 'valid' means being able to be created.

      If you define what you mean by 'valid', it may help with the responses.

      Footnotes:

      1. 1 - Winding back if it doesn't exist might be fun...

      Updates:

      1. +10 minutes - Update formatting and footnotes, and added a more generic response.

      --MidLifeXis

        I misunderstood the OP's question. In this case, I agree with MidLifeXis, try create a dir.
        A tool you can use can be Win32::CreateDirectory, check the return value and message the user afterward
        I didn't successes to use the following regular expressions
        my $dir = "c:\\temp\\%1111 323232?"; if ($dir =~ m/^[a-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$/i) { print "Valid Path\n"; } else { print "Not Valid Path\n"; }
        Please advise - as i wrote i get Path from the user and i need to print error if isn't valid path.