in reply to get contents of directory

This is fairly standard, but I assume you want to create the list of files so that it DOESN'T contain the filename of the list of files? (grin)

my $fn="files.txt"; open OUT,">$fn" || die $!; print OUT grep(!/^$fn$/,map { $_.="\n"; $_ } <*>); close OUT;

This assumes that the current working directory is the one you wish to index. If it is not:

my $dir="thedir"; my $fn="files.txt"; open OUT,">$dir/$fn" || die $!; print OUT grep(!/^$fn$/,map { s/^$dir\///; $_.="\n"; $_ } <$dir/*>); close OUT;

Replies are listed 'Best First'.
Re: Re: get contents of directory
by dkubb (Deacon) on Jan 20, 2001 at 15:13 UTC
    This may be slightly off topic, it sounds to me you're creating something similar to a MANIFEST file. Let me explain what this is..

    On CPAN, every module has a file in it called MANIFEST. It's become a standard part of most perl module distributions. Basically, it's is a list of all the files in the current (and lower directories), along with optional comments beside each file name. It's main purpose is to be a module-wide database of required files, so that during install, any missing files will immediately raise errors from the install process.

    There is a module called ExtUtils::Manifest, which is part of the standard perl distribution, that takes care of reading the current directory, and creating a MANIFEST file for you. As well, inside a file called MANIFEST.SKIP, you can specify a list of regexes that match file names to skip.

    While it's interface it's very elegant, it is functional, and may give you ideas if/when you decide to roll your own manifest writer. Here's some simple example code that will create a MANIFEST with the current directories' contents inside it:

    #!/usr/bin/perl -w use ExtUtils::Manifest qw(mkmanifest); #Optional Configuration $ExtUtils::Manifest::Quiet = 1; #Turn off warnings $ExtUtils::Manifest::Verbose = 0; #Turn off status updates $ExtUtils::Manifest::MANIFEST = 'MANIFEST'; #Filename to write #Will make a MANIFEST file for all the files in your #current directory, including the MANIFEST file mkmanifest();