Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Quickest way to get a list of all folders in a directory

by tokpela (Chaplain)
on Aug 13, 2009 at 14:56 UTC ( #788331=note: print w/ replies, xml ) Need Help??


in reply to Quickest way to get a list of all folders in a directory

Your backslashes in double quotes represents an escaped character. You could use single quotes:

'\\pcname-vm\c$\program files\adobe'

Or you could use double quotes with multiple escaping to compensate for the escaping:

"\\\\pcname-vm\\c$\\program files\\adobe"

Or, finally, you could use forward slashes:
"//pcname-vm/c$/program files/adobe"

Also, you should remove any non-directories from your list.

use strict; use warnings; my $directory = "//pcname-vm/c$/program files/adobe"; open(NDIR, $directory) or die "Error: $!"; my @folders; while (my $filename = readdir(NDIR)) { # skip the . and .. directories next if ($filename =~ /^.+$/); my $folder = "$directory/$filename"; # skip if not a directory next if (! -d $folder); push(@folders, $filename); } close(NDIR); foreach (@folders) { print "$_\n"; }


Comment on Re: Quickest way to get a list of all folders in a directory
Select or Download Code
Re^2: Quickest way to get a list of all folders in a directory
by ig (Vicar) on Aug 13, 2009 at 17:18 UTC
    '\\pcname-vm\c$\program files\adobe'

    In a single-quoted string, '\' is special. See Quote Like Operators, which says:

    A backslash represents a backslash unless followed by the delimiter or another backslash, in which case the delimiter or backslash is interpolated.

    So, your single quoted string should be:

    '\\\\pcname-vm\c$\program files\adobe'
Re^2: Quickest way to get a list of all folders in a directory
by mweb (Initiate) on Aug 13, 2009 at 17:33 UTC
    $/ is the input line separator, set to newline by default. $\ is the output record separator, set to undef by default. Several of these examples have not addressed these. It sounds like the OP is going to iterate over a list of system names and assemble the directory in parts. Single quotes and concatenation recommended:
    my $nodename = 'pcname-vm'; my $directory = '//'.$nodename.'/c$/program files/adobe';

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2014-12-26 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls