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

file manipulation help needed

Status
Not open for further replies.

dulux

Programmer
Sep 4, 2002
36
0
0
GB
Hi all,

I have the following problem and a partial solution.

I have a folder - lets call it A. Within A, I have numbered folders 0-19. I have managed to open all the folders and made them ready for the rest of the operation.

I have a separate folder, called IMAGES, full of JPG's.

I need to open the IMAGES folder (okay so far), then read all the image filenames into an array (trouble brewing).

I am trying to use the following code, but get an error message -

---------------------------------------------------
if(opendir(IMAGES,$imagepath))
{
print"\nopened Converted Image folder okay\n";
}
else
{
print"\n did not open Converted Image folder";
}
while(<IMAGES>)
{
@array=<IMAGES>;
}

-----------------------------------------------------
The error is 'readline() on unopened filehandle IMAGES'

I thought I had opened the file!

I then need to check the name of each image - the name will be numeric - and depending on the result copy the image to one of the numbered folders. The checking of the name is no problem.

Any help is much appreciated - and have a Merry Christmas
 
===
while(<IMAGES>) {...}
===

The <> operator expects a filehandle, not a directory handle (I think - I couldn't find a definitive reference in 60 seconds of searching).

Keep in mind that there's more than one way to do it, but when I have to process all files of a particular type in a directory, this works for me. I used &quot;jpg&quot; as my file extension. If your filesystem is case-sensitive, please adjust accordingly, and if you want to process all files, simply using &quot;*&quot; in glob() should work.

======
while(defined($filename = glob(&quot;<path goes here>/*.jpg&quot;) {

[do something with filename]

}
======
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top