Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

MS system open file with space

by welle (Beadle)
on Feb 20, 2013 at 18:55 UTC ( #1019827=perlquestion: print w/ replies, xml ) Need Help??
welle has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks

It's a trivial question that was already discussed in the past...but unfortunatelly I am not able to make it work. I just want to open in Windows a folder knowing the path and its name. I usually do it with system("start $dir_to_open"). This just works fine exept if the folder name has spaces. I've tried with:

$folder_name="AA BB";
my $dir_to_open = "files\\data\\$folder_name\"; or
my $dir_to_open = "files\\data\\\"$folder_name\""; or
my $dir_to_open = "files/data/\"$folder_name\"";
system("start $dir_to_open");

Windows just prompts an error message (path not found). What I am doing wrong?

Comment on MS system open file with space
Select or Download Code
Re: MS system open file with space
by BrowserUk (Pope) on Feb 20, 2013 at 19:14 UTC

    Use: $path = "c:\\program files"; system qq[ start "" "$path" ];


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: MS system open file with space
by SuicideJunkie (Priest) on Feb 20, 2013 at 19:17 UTC
    Under XP:
    c:\> start c:\
    (Pops explorer window showing c:\)
    c:\> start "c:\program files"
    (Pops useless command prompt window at default directory)
    c:\> start explorer "c:\program files"
    (Pops explorer window at c:\program files)
      c:\> start "c:\program files" (Pops useless command prompt window at default directory)

      That's because the optional first argument to start is a window title.

      If the first argument begins with ", then it is taken as a title -- take a look at the titlebar of that useless command prompt window.

      To disable that effect, prefix the directory with a dummy title:start "" "c:\program files"


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re: MS system open file with space
by Dallaylaen (Scribe) on Feb 21, 2013 at 07:12 UTC
    Writing this without a Windows machine at hand, but what about using list form of system instead? It should escape the arguments for you.
    system ('start', $dir_to_open);
    Does this solve the problem?
      When a pathname includes spaces, windows requires double quotes around the entire path, as BrowserUK has already shown.
      Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-09-01 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (299 votes), past polls