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

I don't know why I see glob so rarely recommended in the monastary. I understand earlier perl versions had some problems on some OSs, but it's fine now (isn't it?)
my @folders = glob('//pcname-vm/c$/program files/adobe/*');
Looks much cleaner, doesn't it? And probably you weren't interested in all of the files in the adobe directory anyway.

I do a bit of this sort of work, here are some other things that might be interesting:
UPdate: correction in code


- Boldra

Replies are listed 'Best First'.
Re: why not glob
by Anonymous Monk on Aug 14, 2009 at 07:00 UTC
    For directories only you want
    grep -d, glob ...
    I don't use glob because it has its own syntaxt and quirks, I find this much clearer to use File::Find::Rule with regex
    #!/usr/bin/perl -- use strict; use warnings; use File::Find::Rule; my $dir = '//pcnamevm/c$/program files/adobe/'; $dir = 'C:/program files/Mozilla Firefox/'; my @folders = File::Find::Rule->directory->maxdepth(1)->in($dir); use DDS; Dump \@folders; __END__ $ARRAY1 = [ 'C:/program files/Mozilla Firefox', 'C:/program files/Mozilla Firefox/chrome', 'C:/program files/Mozilla Firefox/components', 'C:/program files/Mozilla Firefox/defaults', 'C:/program files/Mozilla Firefox/dictionaries', 'C:/program files/Mozilla Firefox/extensions', 'C:/program files/Mozilla Firefox/greprefs', 'C:/program files/Mozilla Firefox/modules', 'C:/program files/Mozilla Firefox/plugins', 'C:/program files/Mozilla Firefox/res', 'C:/program files/Mozilla Firefox/searchplugins', 'C:/program files/Mozilla Firefox/uninstall' ];
      One difference between glob and File::Find::Rule is that the latter also returns the parent directory ('C:/program files/Mozilla Firefox', in your example). It seems the OP does not want that.
        I think that is a bug :D