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!

running perl script over all files in specified directory

Status
Not open for further replies.

TarunMakhija

Programmer
Jun 14, 2005
13
US

Hi,

I am completely new to perl.. and I wanted to modify one code so that it runs over all the files in a directory.

So instead of running the perl script over individual files [input1.txt, input2.txt, input3.txt ....] to get out files [ou1.txt, out2.txt, out3.txt ....] in the following way:

perl delim.pl -in input1.txt -out out1
perl delim.pl -in input2.txt -out out2
perl delim.pl -in input3.txt -out out3
.
.
.

I want to write a FOR loop such that the code iterates over all the "input" text files [input1.txt, input2.txt, input3.txt...]in the specified directory and produces the corresponding "output" text file [out1.txt, out2.txt,....].

I have around 20,000 such files and hence I cannot do it manually - hence the question!

Can someone give me some code for this?

Looking forward to replies,

Thanks,
Tarun Makhija
 
Code:
chdir('path/to/folder') or die "$!";
my @files = <input*.txt>;
for (@files) {
  do whatever you need
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top