Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

directories with spaces

by dhjackal (Initiate)
on Nov 08, 2006 at 09:24 UTC ( [id://582834]=perlquestion: print w/replies, xml ) Need Help??

dhjackal has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I'm fairly new to perl and have stumbled upon a problem creating directories with spaces in the names. For example
my $dir = "D:\Temp\Test directory\Logs" ; $dir =~ s/\\/\//g ; mkdir ($dir) || die "Cannot mkdir $dir: $!" ;
I've tried single and double quotes but to no avail Anybody know the way round this? All help appreciated Declan

Edited (davorg) - added code tags

Replies are listed 'Best First'.
Re: directories with spaces
by davorg (Chancellor) on Nov 08, 2006 at 09:33 UTC

    Well, you're printing out the error message, so don't keep it to yourself - tell us exactly what it says.

    I don't know much about Windows, but I suspect that printing the $dir variable in the error message (as you do) will give you a clue as to what is going wrong.

    Have you trying putting your directory name in single quotes? Does that make any difference? The backslash character has a special meaning in double quotes[1].

    [1] Yes, it has a special meaning in single quotes too. But it's _less_ special :-)

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Thanks davorg, I managed to resolve the issue, the error i was getting was

      Cannot mkdir D:/Temp/ExpImpTest2/Declan test/here/Logs: No such file o +r directory at C:\Documents and Settings\dheerey\Desktop\Development\ +Perl\PSGUtility\test2.pl line 38, <DATA> line 164

      In the end i moved from mkdir to mkpath and removed the double quotes from my path name. The code now looks (and works) like:

      use File::Path ; my $dir = 'D:\Temp\ExpImpTest2\Declan test2\here\Logs' ; $dir =~ s/\\/\//g ; mkpath ($dir) || die "Cannot create $dir: $!" ;

      Thanks again

      20061109 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

        Using <code> tags makes your posts much easier to read, see also Writeup Formatting Tips.

        -- Hofmator

        Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found