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

Searching for specific files in a directory structure

Status
Not open for further replies.

rayarjun1

Technical User
Jul 22, 2009
3
SE
Q1.

Code:
#!/usr/bin/perl -w

$dir=$ARGV[0];
$outdir=$ARGV[1];

opendir(DIR,$dir);
@files=readdir(DIR);
foreach $file(@files)
{
#        if($file=~/\.pdb\.fixed$/)
        if($file=~/\.scwrl$/)
#       if($file=~/\_TS*$/)
        {
                $strideoutfile="$outdir/$file.str";
                `touch $strideoutfile`;
                print "Running Stride on the $file.. \n";

#               next if(-e $strideoutfile &&
#                       -s $strideoutfile > 0);
                `/afs/pdc.kth.se/home/a/arnee/MODULES/scientific/stride/linux/bin//stride $file -f$strideoutfile`;
                 print "script executed \n";
                 print "$strideoutfile \n";
        }
}



Now, I am getting error :

Use of uninitialized value $outdir in concatenation (.) or string at ./stridenew.pl line 14.

Q2. I have files like *_TS* in different folders and I want to pass it as an if command. Any suggestions how?

Q3. The files I just mentioned are in some 600+ folders. Is there any clever way to make this script read into individual folders itself and execute if found with the similar files?



Kindly help and thanks in advance !

Cheers

Aj
 
Q1. Are you specifying 2 parameters on the command-line? If not, $output will not be defined because $ARGV[1] will be empty.

Q2 & Q3. Have you considered using the File::Find module to search through the directories and perform actions on the matching files?

Annihilannic.
 
Hi Annihilannic ,

Thanks for your response .

Q1. I was specifying two file extensions ( *.pdb.fixed and *.scwrl ) to search and run the stride program on. Is that what you wanted to know?

Q2. how can I search something like abc_TS1 through this files and pass it as an if command on the script

Q3. I haven't implemented that. Can you guide me ( mannerism to say.. can you write and show me :D ) about how to use the File::Find module in a script

Thanks a lot

Aj
 
Q1. That sounds wrong since your script seems to be expecting two directory names, not lists of files?

Q2 & Q3. File::Find can match files based on regular expressions and many other things... I don't need to write and show you because there are examples both in this forum and on the perldoc File::Find page... try that and see how it goes. Try searching for 'File::Find' (with the quotes) using the Tek-Tips Google search at the top of this page.

Annihilannic.
 
Hi !

Q1. I misunderstood you. Yeah.. I am giving input and output dir names.

Q2 and 3 . Will be going through it !


Thanks again for the time.

Aj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top