dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Copying a bunch of images to one directory. - shell

This is a discussion on Copying a bunch of images to one directory. - shell ; In stead of reinventing the wheel, someone has to have needed to do this in the past. Does this command line code exist somewhere I can download/look at. I have a directory with over a hundred directories of images in ...


Home > Database Forum > Operating Systems > shell > Copying a bunch of images to one directory.

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 11-24-2007, 04:17 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Copying a bunch of images to one directory.

In stead of reinventing the wheel, someone has to have needed to do
this in the past. Does this command line code exist somewhere I can
download/look at.

I have a directory with over a hundred directories of images in them.
I need to copy all the .png, .gif. JPEG, .jpg files to another
directory in order to burn a CD for a slide show at a Christmas
party.

Can anyone help

TIA
Dave
Reply With Quote
  #2  
Old 11-24-2007, 04:34 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

On 2007-11-24, Dave Kelly wrote:
>
>
> In stead of reinventing the wheel, someone has to have needed to do
> this in the past. Does this command line code exist somewhere I can
> download/look at.
>
> I have a directory with over a hundred directories of images in them.
> I need to copy all the .png, .gif. JPEG, .jpg files to another
> directory in order to burn a CD for a slide show at a Christmas
> party.


If just copying them to the other directory is fine:

cp ./*.png ./*.gif ./*.JPEG ./*.jpg /path/to/other/directory

You may also want to look at mkisofs.

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Reply With Quote
  #3  
Old 11-24-2007, 05:14 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

Dave Kelly wrote:
> In stead of reinventing the wheel, someone has to have needed to do
> this in the past. Does this command line code exist somewhere I can
> download/look at.
>
> I have a directory with over a hundred directories of images in them.
> I need to copy all the .png, .gif. JPEG, .jpg files to another
> directory in order to burn a CD for a slide show at a Christmas
> party.


find -name '*.jpg' -o -name '*.jpeg' | xargs cp --target-directory=/tmp/myporn
or
cp */*.{jpg,jpeg} /tmp/myporn
:-)

--
William Park , Toronto, Canada
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
Reply With Quote
  #4  
Old 11-24-2007, 05:25 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

Chris and William...........

I may have worded my problem badly.

> > I have a directory with over a hundred directories of images in them.


Does you examples step down into each directory? Return to the main
directory and continue looking for the next directory?

Thanks for the feedback.
Dave


Reply With Quote
  #5  
Old 11-24-2007, 06:40 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

Dave Kelly wrote:
> Chris and William...........
>
> I may have worded my problem badly.
>
>
>>>I have a directory with over a hundred directories of images in them.

>
>
> Does you examples step down into each directory? Return to the main
> directory and continue looking for the next directory?


William's 'find' example collects the files from all subdirectories;
wasn't that what you wanted? Did you try the suggestions?

Janis

>
> Thanks for the feedback.
> Dave
>
>

Reply With Quote
  #6  
Old 11-24-2007, 08:50 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

On Nov 24, 4:40 pm, Janis Papanagnou
wrote:

> William's 'find' example collects the files from all subdirectories;
> wasn't that what you wanted? Did you try the suggestions?
>
> Janis


T hat is exactly what I want. No I did not try the suggestion because
of my ignorance of how find works.
Will do so immediatly.

If things do not work as expected, I will come back for further
education. Otherwise assume everything is as it should be. ( As it is
in all cases where there in no operator error.)

Let me say thanks to everyone on this group for all the help they have
given me over the past 8 years. This old man appreciates it.

Dave

Reply With Quote
  #7  
Old 11-25-2007, 09:28 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

On Nov 24, 4:40 pm, Janis Papanagnou
wrote:
> William's 'find' example collects the files from all subdirectories;
> wasn't that what you wanted? Did you try the suggestions?
>
> Janis
>

Tried this:
find -name '{*.jpg,*.png,*.JPG,*.gif}' -o -name
'{*.jpg,*.png,*.JPG,*.gif}' | xargs cp --target-directory=~/
xmasparty07
And got this error
cp: missing file argument

Tried this:
SilverNail:~/tffwebsite/httpdocs/images# find -name '*.jpg' -o -name
'*.jpg' | xargs cp --target-directory=~/xmasparty07
And got this error
cp: `~/xmasparty07': specified destination directory does not exist

Tried this:
find -name '*.jpg' --o name '*.jpg' | xargs cp --target-directory=/
root/xmasparty07
And got this error
cp: cannot stat `enhanced': No such file or directory
cp: cannot stat `1.jpg': No such file or directory
cp: cannot stat `./Belize2005/Norbert': No such file or directory
cp: cannot stat `Bonefish': No such file or directory
cp: cannot stat `at': No such file or directory

So I tried --o name "'*.jpg'" and -o name '"*.jpg"' and
still get the cannot stat errors.

Reply With Quote
  #8  
Old 11-25-2007, 11:59 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

On Sun, 25 Nov 2007 17:28:35 -0800 (PST), Dave Kelly wrote:
| On Nov 24, 4:40 pm, Janis Papanagnou
| wrote:
|> William's 'find' example collects the files from all subdirectories;
|> wasn't that what you wanted? Did you try the suggestions?
|>
|> Janis
|>
| Tried this:
| find -name '{*.jpg,*.png,*.JPG,*.gif}' -o -name
| '{*.jpg,*.png,*.JPG,*.gif}' | xargs cp --target-directory=~/
| xmasparty07
| And got this error
| cp: missing file argument
|
| Tried this:
| SilverNail:~/tffwebsite/httpdocs/images# find -name '*.jpg' -o -name
| '*.jpg' | xargs cp --target-directory=~/xmasparty07
| And got this error
| cp: `~/xmasparty07': specified destination directory does not exist
|
| Tried this:
| find -name '*.jpg' --o name '*.jpg' | xargs cp --target-directory=/
| root/xmasparty07
| And got this error
| cp: cannot stat `enhanced': No such file or directory
| cp: cannot stat `1.jpg': No such file or directory
| cp: cannot stat `./Belize2005/Norbert': No such file or directory
| cp: cannot stat `Bonefish': No such file or directory
| cp: cannot stat `at': No such file or directory
|
| So I tried --o name "'*.jpg'" and -o name '"*.jpg"' and
| still get the cannot stat errors.


The stat errors look like the typical result of files with spaces in
their names. Find locates them correctly, but xargs breaks them up on
the space characters.

Assuming your versions support the options, try this:

find -name '*.jpg' -o -name '*.gif' -print0 | \
xargs -0 cp --target-directory=/root/xmasparty07

The '-print0' and '-0' contain a numeric 0, not the upper case letter O

This uses a NULL character (ASCII zero) as the word separator instead of
spaces.


--
Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/~paulcol
Asking for technical help in newsgroups? Read this first:
http://catb.org/~esr/faqs/smart-questions.html#intro
Reply With Quote
  #9  
Old 11-26-2007, 04:55 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

On 26 Nov., 02:28, Dave Kelly wrote:
> On Nov 24, 4:40 pm, Janis Papanagnou
> wrote:> William's 'find' example collects the files from all subdirectories;
> > wasn't that what you wanted? Did you try the suggestions?

>
> > Janis

>
> Tried this:
> find -name '{*.jpg,*.png,*.JPG,*.gif}' -o -name
> '{*.jpg,*.png,*.JPG,*.gif}' | xargs cp --target-directory=~/
> xmasparty07
> And got this error
> cp: missing file argument
>
> Tried this:
> SilverNail:~/tffwebsite/httpdocs/images# find -name '*.jpg' -o -name
> '*.jpg' | xargs cp --target-directory=~/xmasparty07
> And got this error
> cp: `~/xmasparty07': specified destination directory does not exist
>
> Tried this:
> find -name '*.jpg' --o name '*.jpg' | xargs cp --target-directory=/
> root/xmasparty07
> And got this error
> cp: cannot stat `enhanced': No such file or directory
> cp: cannot stat `1.jpg': No such file or directory
> cp: cannot stat `./Belize2005/Norbert': No such file or directory
> cp: cannot stat `Bonefish': No such file or directory
> cp: cannot stat `at': No such file or directory
>
> So I tried --o name "'*.jpg'" and -o name '"*.jpg"' and
> still get the cannot stat errors.


Does the man page of your find command specifies to write two slashes
with option -o? Option 'name' requires a slash -name. Quoting of the
find arguments is necessary to prevent the shell to expand the names
to a matching file in the current directory and thereby producing
errors or wrong results; use just one pair of quotes, either single or
double (the latter in case you want to have shell variables inside the
string expanded before find is called). Try

find . -name "*.jpg" -o -name "*.gif" -o -name "*.png" -print0 |
xargs -0 cp --target-directory=/root/xmasparty07

Add more filename (patterns) by using a -o ("or") and -name.
(The 0 is a zero digit in case your font obscures it.)

Janis
Reply With Quote
  #10  
Old 11-26-2007, 08:52 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Copying a bunch of images to one directory.

The -exec option of find handles spaces in filenames correctly:

find -name \*.png -o -name \*.gif -o -name \*.JPEG -exec
cp {} \;

And it also works with non-GNU versions of find and cp.
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 02:24 AM.