Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Creating a txt file with paths to all files

by anju (Initiate)
on Jun 19, 2002 at 16:10 UTC ( #175748=perlquestion: print w/replies, xml ) Need Help??

anju has asked for the wisdom of the Perl Monks concerning the following question:

I need a text file which has the paths to all the files within the drive. Is it possible with perl? I should get a text file with something like this: C:\cars\toyota\new.jpg C:\cars\honda\civic\new.tif .......etc Can someone help me out?
  • Comment on Creating a txt file with paths to all files

Replies are listed 'Best First'.
Re: Creating a txt file with paths to all files
by earthboundmisfit (Chaplain) on Jun 19, 2002 at 16:20 UTC
    Sounds like a job for File::Find
    #! Perl -w use strict; use File::Find; my $fdir='C:'; my @filelist = (); find(\&wanted, $fdir); write_file() if (@filelist); sub write_file() { .... # sub that writes @filelist to a text file } sub wanted { my $thisfile = $File::Find::name; push(@filelist, $thisfile) if ($thisfile =~ m/\.txt/); #for ex +ample }
    hth
Re: Creating a txt file with paths to all files
by jepri (Parson) on Jun 19, 2002 at 16:19 UTC
    Yep, just read up on the File::Find module by Jarkko. You already have it installed.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Re: Creating a txt file with paths to all files
by Caillte (Friar) on Jun 19, 2002 at 16:18 UTC
    `dir /s/b c:\ > x.txt`;

    This page is intentionally left justified.

Re: Creating a txt file with paths to all files
by zentara (Archbishop) on Jun 19, 2002 at 16:31 UTC
    Here's a simple script using File::Find: Just run it from the top directory, use / for the whole filesystem, and run it as root. To output it to a textfile: ./filelister > my.txt
    #!/usr/bin/perl #filelister # Recursively searchs down thru directories for files use warnings; use strict; use File::Find; find (\&found,"."); $" = "\n"; print "@ARGV\n"; exit; sub found{ push @ARGV, $File::Find::name if -f; }
Re: Creating a txt file with paths to all files
by caedes (Pilgrim) on Jun 19, 2002 at 16:20 UTC
    Since you are on windows you can do it easily enough with one DOS command from the C: root directory:
    dir /s /b > file.txt
    Edit: ok,ok... I'm slow. Geez. :-\
      If you had a real operating system you could do this ...
      find / > allfiles
Re: Creating a txt file with paths to all files
by stefp (Vicar) on Jun 19, 2002 at 19:08 UTC
    I don't know the motivation behind your question. But you may look at slocate before reinventing wheels. It allows to store in a efficient manner such a list of file and to search on that list. It may even be supported on Windows.

    I got the URL from the rpm package but it seems wrong. Probably the right URL may be found trhu google

    -- stefp -- check out TeXmacs wiki

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2022-10-02 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (13 votes). Check out past polls.

    Notices?