Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Files recursively without using Modules.

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
0
0
Could you please provide me with a code snippet or something where we can read the files recursively.
Say If I have a root folder and folders within them with files. I want to read the files recursively.

dir1
dir2
dir3 -> Files
dir4 -> Files
dir5
dir6 -> Files

and so on.

I want to read all the files and want to store the path to those files.

Could someone provide me with some tips.

Thanks


 
Take a look at opendir and readdir functions of perl.

or on your prompt you could try
Code:
> perldoc opendir

and

> perldoc readdir


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
As a matter of interest, why don't you want to use modules? File::Find is a standard module that ships with most, if not all, Perl distributions and will do recursive file iteration for you.
 
I wholeheartedly agree with ish on File::Find, it's been standard since 5.005 or something, you have the module, you'll really thank yourself for using it.

But, long ago before I knew of such things, I wrote something that recursively copied files in thread219-541056, it could be easily altered to do whatever task you need.

________________________________________
Andrew

I work for a gift card company!
 
Here's another example without File::Find:
thread219-1038148

 
I find that File::Find is decent for simple stuff. For recursive travesals with more specific operations in mind opendir, readdir, and chdir are simple and effective... if you have a good algorithm of course :)

./james
 
I would like to tweak the readdir and implement my own solution. Where I have a fixed format of directories and then have a list of files within each directory that I want to distinguish based on their timestamps and store the timestamps and the path and the filename in a hash so that I can then compare all the folders and files under a directory and then place the files in a shared area based on their file extensions.

I would like to use File stat and do a recurisve lookup of folders for all the files with a particular extension.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top