Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: how to dir a directory that have space

by BrowserUk (Patriarch)
on Jan 16, 2015 at 08:42 UTC ( [id://1113452]=note: print w/replies, xml ) Need Help??


in reply to Re: how to dir a directory that have space
in thread how to dir a directory that have space

use system(@list) form instead:

That does nto work on windows!

The simplest solution to the OP's problem is:

my $source_directory = 'E:\\common\compare\latest folder\PDF\DB\\'; `dir \"$source_directory\" /b/s /o:-d`;

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. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^3: how to dir a directory that have space
by vkon (Curate) on Jan 16, 2015 at 10:15 UTC
    works for me,
    perl -we "system('dir','/b/s','/o:-d',shift)" "Program Files" C:\Program Files\Internet Explorer C:\Program Files\Microsoft Office C:\Program Files\Syncplicity C:\Program Files\McAfee C:\Program Files\WinDjView C:\Program Files\Synaptics C:\Program Files\Realtek C:\Program Files\Microsoft Silverlight C:\Program Files\Windows Journal C:\Program Files\Java C:\Program Files\Microsoft Policy Platform C:\Program Files\Common Files C:\Program Files\Lenovo C:\Program Files\Courion Corporation C:\Program Files\Windows Defender ...
    indeed, there was dir.exe in cygwin in my setup that I needed to expunge before running the one-liner

      Well I never, bless my soul, so it does. (In this case...) I stand corrected!

      On Windows, parameters are passed to executables as a single string, so the list forms of system & open etc., join the list into a single string before calling CreateProcess().

      There is some intelligence involved in the concatenation, but in many, (by my experience: most) cases, that 'intelligence' flies in the face of expectation, and gets it wrong.


      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. Agile (and TDD) debunked

      By way of example of the inconsistent nature of the internal handling of the list form:

      system 'perl', '-E', 'say 12345;';; ## Works! 12345 system 'perl', '-E', 'say "hello world";';; ## Doesn't work. system 'perl', '-E', 'say \"hello world\";';; ## Doesn't work. system 'perl', '-E', '"say \"hello world\";"';; ## Works! hello world system 'perl', '-E', '\"say \"hello world\";\"';; ## Doesn't work, Can't find string terminator '"' anywhere before EOF at -e line 1.

      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. Agile (and TDD) debunked
Re^3: how to dir a directory that have space
by AtlasFlame (Novice) on Jan 16, 2015 at 09:09 UTC

    No it does not work.

      No it does not work.

      Works for me:

      C:\test>perl -we"my $dir = 'c:\\program files\\'; print for `dir \"$di +r\" /s /b /o:-s`" c:\program files\7-Zip c:\program files\Bin c:\program files\Common Files c:\program files\Core Temp c:\program files\CPUID c:\program files\Direct Modeling Express 4.0 c:\program files\Extras c:\program files\GlowCode 9.0 c:\program files\Hitman Pro 3.5 ...

      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. Agile (and TDD) debunked

        It works ok if run it in single line. But when i put it in script it does not. Anyway i'm using below code to do the same and it's working ok. Basically i'm searching for newest specific file name in sub-folders that starts with "K"

        opendir my $dh, $source_directory or die "error: open '$source_directo +ry'"; my @paths = grep { /^K/} readdir $dh; closedir $dh; $p=0; foreach (@paths){ opendir SUB_DIR,"$source_directory$paths[$p]"; while(our $file = readdir(SUB_DIR)) { if(($file =~ /$ID/) && ($file =~ /xls$/)){ @files = $file; @FilePath = "$source_directory$paths[$p]"; } } $p++; } print "\nFile = $FilePath[0]\\$files[0]\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found