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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Directories and Files

Status
Not open for further replies.

aspnetx

Technical User
Joined
Apr 3, 2007
Messages
4
Location
US
I'm trying to create a Perl program to read a directory and the files in them. The directory structure looks like this....

cd /devt/prod/retrans/epix change to directory

contents of this directory has directories in it dyearmonthday...

drwxrwxr-x 2 settlec settle 40960 Feb 17 21:25 d20070217
drwxrwxr-x 2 settlec settle 40960 Feb 18 21:14 d20070218
drwxrwxr-x 2 settlec settle 40960 Feb 19 21:28 d20070219
drwxrwxr-x 2 settlec settle 49152 Feb 20 21:13 d20070220
drwxrwxr-x 2 settlec settle 49152 Feb 21 22:46 d20070221
drwxrwxr-x 2 settlec settle 49152 Feb 22 21:18 d20070222

I need the contents inside these directories. Example.... Inside the directories are zipped files referenced with 6 digit numbers like so...

cd /devt/prod/retrans/epix/d20070217

RPT_EP009188.Z RPT_EP472779.Z RPT_EP577433.Z RPT_EP809002.Z TRX_EP443690.Z TRX_EP588776.Z USER_EP583750.Z

What I need is a Perl program to pull all of the contents of the 6 digit number that I specify in this directory. So, if I say show me all the files that contain 009188. It will give a list of all the files that contain 009188 and the UNIX path.

 
Here is the Perl script I used to get a list of the contents in a directory.... I'm not a Perl programmer... I'm just starting out with Perl....

#! /usr/bin/perl -wT

opendir(DIRHANDLE, "/prod/retrans/epix") or die "couldn't open /prod/retrans/epix : $!";
while ( defined ($filename = readdir(DIRHANDLE)) ) {
print "In /prod/retrans/epix is something called $filename\n";
}
closedir(DIRHANDLE);
 
check out the File::Find module.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks for your help......
 
Ok.... I was able to put together this script to list the directory names..

#!/usr/bin/perl -w

use File::Find;
use strict;

# defenitions
my (@good_dirs) = ( "/prod/retrans" );
my $ltotal = 0;

#Find Directories and Subroutine
File::Find::find({wanted => \&wanted}, @good_dirs);
print "\nFound a total of $ltotal instances.\n";

sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);

if ((($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-d _ && /^epix\z/s ) {
$ltotal++;
print "$ltotal $File::Find::name\n";
}
}
"FindEPIX.pl" 24 lines, 508 characters
/export/home/khande/perl:>> ./FindEPIX.pl
1 /prod/retrans/epix
2 /prod/retrans/tv/epix

Now what i need is a way to pull every instance of a 6 digit part_id from all of these directories listed below. The file format is
RPT_EP009188.Z RPT_EP472779.Z RPT_EP577433.Z RPT_EP809002.Z TRX_EP443690.Z TRX_EP588776.Z USER_EP583750.Z

I need my program to ask me for what ever part_id, then search all the directories listed below and output what it finds to the screen along with the pathnames.

/prod/retrans/epix:>> ls
d20070218 d20070223 d20070228 d20070305 d20070310 d20070315 d20070320 d20070325 d20070330 m20070228
d20070219 d20070224 d20070301 d20070306 d20070311 d20070316 d20070321 d20070326 d20070331 m20070331
d20070220 d20070225 d20070302 d20070307 d20070312 d20070317 d20070322 d20070327 d20070401
d20070221 d20070226 d20070303 d20070308 d20070313 d20070318 d20070323 d20070328 d20070402
d20070222 d20070227 d20070304 d20070309 d20070314 d20070319 d20070324 d20070329 d20070403
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top