Le jeu, jui 20, 2006 at 09:36:02 -0700, Nishi Bhonsle a tapoté sur son clavier :
> 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.
> 
> Thanks in advance! -Nishi.


Hi,

You should look at Basename on the CPAN -->
http://search.cpan.org/~cwest/ppt-0.14/bin/basename

Regards,


-- 
. ''`.  (\___/) E d i   S T O J I C E V I C 
: :'  : (='.'=) http://www.debianworld.org  
`. `~'  (")_(") GPG: C360 FCF0 AB3A 2AB0 52E7 044F 1B3D 2109 1237 B032  
  `-     

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to