I tried it but didnt work.
my @new;
find(sub {push @new, $_}, $path);
open FILE,">>$logfile";
print FILE "$_\n" foreach @new;
close FILE;
In addition to printing filenames and directories, it also printed the "."
The log file contained
.
file1.txt
file2.txt
How can I not include the "." ?
Thanks!
-Nishi.
On 7/21/06, Rob Dixon <[EMAIL PROTECTED]> wrote:
Nishi Bhonsle wrote:
> Hi:
> I am starting a new thread based of an older thread just because there
> was a
> lot of different things that were requested for and it had gotten a bit
> confusing.
>
> I got a lot of help from all you experts to write the below code that
takes
> an argument path C:\build\Sample\NewDir that contains--
>
> C:\build\Sample\NewDir\File1.txt
> C:\build\Sample\NewDir\File2.txt
> C:\build\Sample\NewDir\NewSubDirectory
> C:\build\Sample\NewDir\NewSubDirectory\11.txt
>
> and prints out the following into the output file --
> File1.txt
> File2.txt
> NewSubDirectory
>
> use strict;
> use warnings;
>
> my $path = $ARGV[0];
>
> opendir DIR, $path or die "Can't open $path: $!";
>
> my @new = grep { $_ ne "." and $_ ne ".." } readdir DIR;
> closedir DIR;
>
> open FILE,">>c:/buildlist2.txt";
> print FILE "$_\n" foreach @new;
> close FILE;
>
> Can I modify the above code so that no directory name is printed in the
> ouputfile but only filenames are printed. ie File1.txt and File2.txt are
> printed in the output file without the NewSubDirectory printed in it? I
am
> looking for some way that before getting the entries into the new array,
i
> can remove the entries that stand for directory names.
>
> I tried using find(sub {push @new, $_ if -f}, $path); but that prints
all
> the filenames under NewDir as well as NewSubDirectory together which is
not
> what i need. For getting files under NewSubDirectory, I will issue a
> separate command with argument path as
> C:\build\Sample\NewDir\NewSubDirectory and hence this command does not
work
> since it clubs files and directories and files within sub-directories.
>
> I tried using find(sub {push @new, $File::Find::name}, $path); but that
> prints the directories and files along with their complete/absolute
paths,
> which is not what i need.
Just change it to
find(sub {push @new, $_}, $path);
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>