467,114 Members | 1,302 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,114 developers. It's quick & easy.

readdir in subdirs

Hello
Expand|Select|Wrap|Line Numbers
  1. opendir(DIR, ".");
  2.     @FILENAME = readdir(DIR);
  3.     closedir(DIR); 
Now here u see a script that gets file names in dir the script is in, but how i could also readdir in every subdir the script directory has?
Oct 11 '08 #1
  • viewed: 3076
Share:
8 Replies
eWish
Expert 512MB
Check out File::Find.

--Kevin
Oct 11 '08 #2
But can you do that without the File::Find?
Oct 11 '08 #3
numberwhun
Expert Mod 2GB
But can you do that without the File::Find?
File::Find would be the easiest way. If you are unable to install the module, you can still download the code and see how the module does it and incorporate that code into yours. Either way, its easier.

Regards,

Jeff
Oct 11 '08 #4
Ok now i have File::Find and found this script somewhere
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use File::Find;
  3. @ARGV = '.' unless @ARGV;
  4.  
  5. find sub {
  6.     print "got one!\n" if m/\.mp3$/;
  7. }, @ARGV;
How i could make this script work like the one i used before? Like how i could get the files found to go to @FILENAME
Oct 11 '08 #5
numberwhun
Expert Mod 2GB
Ok now i have File::Find and found this script somewhere
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use File::Find;
  3. @ARGV = '.' unless @ARGV;
  4.  
  5. find sub {
  6.     print "got one!\n" if m/\.mp3$/;
  7. }, @ARGV;
How i could make this script work like the one i used before? Like how i could get the files found to go to @FILENAME
Well, instead of doing the print, you could modify it to do a push() to the array. Look up the push function on perldoc and you will see how to do it.

Regards,

Jeff
Oct 11 '08 #6
kk thanks, i will use this now, but i would still like to know how u would do it without File::Find
Oct 11 '08 #7
KevinADC
Expert 2GB
kk thanks, i will use this now, but i would still like to know how u would do it without File::Find
Write a recursive function. Google would have found you a number of examples. Learn how to use search engines for your pleasure and benefit.

http://www.bin-co.com/perl/scripts/dir.php
Oct 11 '08 #8
eWish
Expert 512MB
After reading the article that Kevin linked to File::Find is looking even better. I personally like File::Find::Wanted. However, File::Find is standard and File::Find::Wanted is not.

--Kevin
Oct 12 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Oliver | last post: by
7 posts views Thread by Ask Josephsen | last post: by
5 posts views Thread by Florian Lindner | last post: by
4 posts views Thread by MZ | last post: by
9 posts views Thread by Confused but working on it | last post: by
1 post views Thread by mukeshrasm | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.