Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: How to validate windows path

by roteme (Acolyte)
on Mar 13, 2012 at 16:59 UTC ( [id://959411]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to validate windows path
in thread How to validate windows path

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.

Replies are listed 'Best First'.
Re^5: How to validate windows path
by tobyink (Canon) on Mar 13, 2012 at 21:28 UTC

    A regular expression to check whether a path is valid or not would be quite a substantial piece of work. For example...

    C:\BON - a valid path C:\CON - not valid

    (Aside: "CON" is a special device representing the console itself, so files and directories are not allowed to be called "CON". There are other devices with similar effect. Unixey operating systems have a similar feature, however absolute paths were always used, so while you cannot name a file "/dev/stdin" in Unix, you can create "stdin" files in other directories.)

    Do what everyone else has said - just go ahead and try to create the directory, then check that it exists (i.e. that creation worked).

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^5: How to validate windows path
by MidLifeXis (Monsignor) on Mar 13, 2012 at 18:40 UTC

    What did you get when you ran it? I received an error message that points out very well where I (well, the code) has an error in it.

    Unmatched [ in regex; marked by <-- HERE in m/^[a-z]:\\(?:[ <-- HERE ^\\/ at foo.pl line 3.

    You need to escape the 'end of regexp' marker to move beyond this.

    --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://959411]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-23 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found