CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help Separating a collection of Images

 



Beginner Joe
New User

Mar 8, 2014, 9:09 PM

Post #1 of 6 (1738 views)
Help Separating a collection of Images Can't Post

I have a directory containing three types (sizes) of images (ex: gm0013a.jpg) all ending in either a.jpg b.jpg or c.jpg, depending upon their size. My question is, how would I write a program to copy/move only the files ending in a.jpg to a separate directory using perl. Thanks for any help you can give me.


Laurent_R
Veteran / Moderator

Mar 9, 2014, 3:15 AM

Post #2 of 6 (1737 views)
Re: [Beginner Joe] Help Separating a collection of Images [In reply to] Can't Post

Hi,

you can use the glob function to make a list of files ending with "a.jpg":


Code
my @list_of_files_to_be_copied = glob ("*a.jpg");


and then process the list of files thus generated.

This is an example of a Perl one-liner with which I copied the files ending with "a.pl" of my current directory (I don't have jpg files here) to a "new_dir" directory:


Code
$ perl -e 'link $_, "./new_dir/$_" for glob ("*a.pl")' 

$ ls new_dir
a.pl proc_data.pl



Beginner Joe
New User

Mar 9, 2014, 9:46 AM

Post #3 of 6 (1734 views)
Re: [Laurent_R] Help Separating a collection of Images [In reply to] Can't Post


In Reply To
Hi,

you can use the glob function to make a list of files ending with "a.jpg":


Code
my @list_of_files_to_be_copied = glob ("*a.jpg");


and then process the list of files thus generated.

This is an example of a Perl one-liner with which I copied the files ending with "a.pl" of my current directory (I don't have jpg files here) to a "new_dir" directory:


Code
$ perl -e 'link $_, "./new_dir/$_" for glob ("*a.pl")' 

$ ls new_dir
a.pl proc_data.pl

Hi,
I tested this and the first part worked perfectly as it stored all the correct named images. But the "copy to new_directory" part didn't work and didn't return any errors when I ran it. I used the same syntax you did, so I'm not sure what went wrong.



Laurent_R
Veteran / Moderator

Mar 9, 2014, 4:28 PM

Post #4 of 6 (1717 views)
Re: [Beginner Joe] Help Separating a collection of Images [In reply to] Can't Post

Please show the code that you used for your test, I can't guess any mistake that you did. My example worked, but in a slightly different setting, you might need some additional processing.


Beginner Joe
New User

Mar 10, 2014, 9:21 AM

Post #5 of 6 (1538 views)
Re: [Laurent_R] Help Separating a collection of Images [In reply to] Can't Post

The problem was that I wasn't ending my line with the semicolon. Problem solved. Thanks for your help in getting this solved.


Laurent_R
Veteran / Moderator

Mar 10, 2014, 10:54 AM

Post #6 of 6 (1514 views)
Re: [Beginner Joe] Help Separating a collection of Images [In reply to] Can't Post

You are welcome.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives