Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses


by jrsmith (Pilgrim)
on Apr 26, 2000 at 23:32 UTC ( #9308=perlquestion: print w/replies, xml ) Need Help??
jrsmith has asked for the wisdom of the Perl Monks concerning the following question:

i'm developing a script under win32 that searches through directories looking for a directory with certain characters in it's name. i'm relativley new to perl just FYI. i have 2 problems:

1- the script will work under NT but not 9x. i figure this has something to do with the file systems but i'm not exactly sure what. any ideas?

2- i need the script to look at ONLY directories, not directories and files. i assume i can do this with and if expression testing whether i could opendir it but i was just wondering if there was any easier way.

thanx and please be gentle i am but a simple newbie.

Replies are listed 'Best First'.
Re: directories
by chromatic (Archbishop) on Apr 26, 2000 at 23:50 UTC
    A good module that does similar things is File::Find. If you get really stuck, you might take a look at its guts. As to your two questions:
    1. There shouldn't be any file system level differences... it's more likely you've accidentally used an option which isn't supported on ActiveState's interpreter for 9x. (fork() and alarm() come to mind)
    2. The -X test will help you here. Specifically:
      if (-d $filename) { print "$filename is a directory.\n"; } else { print "$filename is a file. Skipping...\n"; }
Re: directories
by turnstep (Parson) on Apr 26, 2000 at 23:53 UTC

    It should work on both. What exactly is going wrong?

    You can test a filehandle or a filename with the -d file test operator, which returns true if the file is a directory, false if not, and undefined if the file was not found:
    for $x ("windows", "sheep", "etc") { if (-d $x) { print "Found directory: $x\n"; } }
Re: directories
by BBQ (Deacon) on Apr 27, 2000 at 03:22 UTC
    Coincidentally, I asked from the wisdom of the monks on a little sub I wrote on this node. My problem was that the script was working and I didn't thing it should have.

    It works fine on everything I tested (Linux, NT, 95, 98 and BeOS). Just remember that on Win machines you have to indicate what HD you're running off of, ie:
    my $dir = 'd:/temp';
    or else it will run from the place you called it...


    # Trust no1!
Re: directories
by jrsmith (Pilgrim) on Apr 27, 2000 at 08:26 UTC
    thanx to you all i believe the -d test operator will solve my problems :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://9308]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2018-05-21 23:02 GMT
Find Nodes?
    Voting Booth?