473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

readdir in subdirs

31
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
8 3329
eWish
971 Expert 512MB
Check out File::Find.

--Kevin
Oct 11 '08 #2
über
31
But can you do that without the File::Find?
Oct 11 '08 #3
numberwhun
3,509 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
über
31
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
3,509 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
über
31
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
4,059 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
971 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

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

Similar topics

8
by: Oliver | last post by:
Hi, I wrote earlier this day about this problem but thought it had something to do with images. However, I found out that for some reason the readdir function is not working properly on my Suse...
7
by: Ask Josephsen | last post by:
Hi NG In wich order does "readdir()" read files from the disc? I've got an image folder with images in the format "00001.jpg", "00002.jpg" etc. It seems "readdir()" read the lowest first, but is...
5
by: Florian Lindner | last post by:
Hello, how can I get all subdirectories of a given directory. os.listdir(dir) doesn't differentiate between directories and files, os.walk seems to me a bit overkill since it also descends in the...
2
by: Matt | last post by:
Hello, I am writing a script that opens needs to get a listing of files in a directory, print that listing to a file and use that file as a quasi ftp control file. My problem is that when I...
0
by: Neil | last post by:
I have an existing code base that I want to import into VS 7.1 C++. It has 200+ include files in 20+ subdirs. e.g. incl/package/classfile.h incl/package2/classfile2.h I want to add all of...
2
by: Evan Carmi | last post by:
hey, i am trying to move files with a specific file-ending (.msf) to dir above their current location. my code so far works as long as all the files are on the same dir level. but how can i...
4
by: MZ | last post by:
Hello! I have written such function... Unfortunately images are not sorted by filename and I don`t know why. I have such files placed in subfolder: ...
9
by: Confused but working on it | last post by:
Just wanted to say thanks for the posts helping me make ths work. Added a few comments and after the readdir used a pattern match to test for ..jpg, and seems to work fine on my test setup. Maybe I...
1
by: mukeshrasm | last post by:
Hi, When I used readdir() function and echo the file name it prints . and .. as well.Whereas there is no such file with name . or.. , so why it is printing it. What does it mean? And one more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.