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

I need quick help - editing a number of files in a folder

Status
Not open for further replies.

c4n

Programmer
Mar 12, 2002
110
SI
He're ste idea:

I have a folder with a number of files. Now I want the script to open every file and do something with it (let's say print something in). What "trick" do I use so the script will do this, but the number of file sis not allways the same?

The real problem is how to "split" a number, let's say "100" to numbers "1, 2, 3, ..., 99, 100". I want to make an array @numbers with all these numbers:

@numbers = "1, 2, 3, ..., 99, 100";

and if the number of files is 200

@numbers = "1, 2, 3, ..., 199, 200";

The number of files is constantly growing so I can't write the @numbers in script, because it changes all the time (new values are added).


Any ideas?

Thanks!
 
I'm assuming that you are using PERL, if you are, this should work:
opendir(FILES, "./dir");
@files = <FILES>;
closedir(FILES);
$max = @files;
@array = 1 .. $max; //Daniel
 
Correction:
Replace
@array = 1 .. $max;
with
@array = (1 .. $max); //Daniel
 
It works :) And yes, Perl is my language of choice :)

Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top