Frank 'Olorin' Rizzi wrote:

>Hello everybody.
>
>I am just starting with Perl,
>so the following question will probably appear simple to most of you.
>
>I am trying to get a Perl program to provide me with a listing of the files
>stored on the machine (where the program runs).
>The environment is a Win machine..
>
>Say I have something like the following:
>
>#!/usr/bin/perl
>
>use File::Find;
>use Win32API::File ":ALL";
>
>foreach (getLogicalDrives())
>   {
>   my $dir = $_;
>
>   next unless (GetDriveType($_) == DRIVE_FIXED);
>
>// HERE
>
    There are a three options

    1) Glob operator
           print while (<*>);
          This will print all files in the current directory. This can 
be modified to list files inside any directory
           with a
           while (<$dir/*>) # $dir contains the target directory path
             Relevant docs :
            perldoc -f glob
            perldoc File::Glob

      2) opendir, readdir and closedir
           opendir DIRHANDLE, $dir # Open the directory $dir for reading 
through the handle DIRHANDLE
            print for (readdir (DIRHANDLE));
            closedir (DIRHANDLE); # Close the handle

            Difference this method and the glob method is pathname returned.
            Using glob the output will be
            $dir/file.txt $dir/subdir1 (Assuming file.txt is a file 
subdir1 is a directory inside $dir)
            Using readdir the output will be
             file.txt subdir1 (Note that $dir/ is not prefixed)
            Docs : perldoc -f opendir
                       perldoc -f readdir
                       perldoc -f closedir

      3) Using File::Find
           use File::Find;
           find (sub { print $File::Find::name }, $dir);
           
           This will recursively print all files and sub-directories 
within $dir
            Docs : perldoc File::Find

     HTH,
     Sudarsan
         

>
>
>   }
>
>What would you put where the //HERE line is in order to get a directory
>listing of the $dir ?
>Is there anyway I can have this directory listing to immediatly expand
>subdirectories, or should I make it a recursive sub ?
>
>Thank you in advance,
>
>Frank 'Olorin' Rizzi
>e-mail: [EMAIL PROTECTED]
>or [EMAIL PROTECTED]
>
>
>
>
>




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to