Copying a bunch of images to one directory.

Copying a bunch of images to one directory.

am 24.11.2007 21:17:04 von Dave Kelly

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

Re: Copying a bunch of images to one directory.

am 24.11.2007 21:34:19 von cfajohnson

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

Re: Copying a bunch of images to one directory.

am 24.11.2007 22:14:36 von William Park

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/

Re: Copying a bunch of images to one directory.

am 24.11.2007 22:25:57 von Dave Kelly

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

Re: Copying a bunch of images to one directory.

am 24.11.2007 23:40:19 von Janis Papanagnou

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
>
>

Re: Copying a bunch of images to one directory.

am 25.11.2007 01:50:22 von Dave Kelly

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

Re: Copying a bunch of images to one directory.

am 26.11.2007 02:28:35 von Dave Kelly

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.

Re: Copying a bunch of images to one directory.

am 26.11.2007 04:59:04 von Paul Colquhoun

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

Re: Copying a bunch of images to one directory.

am 26.11.2007 09:55:38 von Janis Papanagnou

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

Re: Copying a bunch of images to one directory.

am 26.11.2007 13:52:59 von Othmar Wigger

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.

Re: Copying a bunch of images to one directory.

am 26.11.2007 13:57:14 von Rikishi 42

On 2007-11-26, 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.

Try this:
find source_dir/ -iname "*.jpg" -exec cp -v '{}' target_dir/ ';'
find source_dir/ -iname "*.png" -exec cp -v '{}' target_dir/ ';'

The iname option ignores case.
Remove the -v option from cp, if you want less display (and more speed).


--
There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
Douglas Adams

Re: Copying a bunch of images to one directory.

am 26.11.2007 14:01:13 von Rikishi 42

On 2007-11-26, Rikishi 42 wrote:
> Try this:
> find source_dir/ -iname "*.jpg" -exec cp -v '{}' target_dir/ ';'
> find source_dir/ -iname "*.png" -exec cp -v '{}' target_dir/ ';'
>
> The iname option ignores case.
> Remove the -v option from cp, if you want less display (and more speed).

Some other post taught me the -o option of find, which I didn't know.

So, the following should do:
find source/ -iname "*.jpg" -o -iname "*.png" -exec cp -v '{}' target/ ';'

Have fun!

--
There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
Douglas Adams

Re: Copying a bunch of images to one directory.

am 27.11.2007 11:36:38 von parv

in message <5e6fa$4748943c$d1520b22$4446@PRIMUS.CA>,
wrote William Park ...

> 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

That find(1)s only the files with suffix of 'jpeg' here on FreeBSD
(6-STABLE). To find files named '*.jpg', need to collect the -name
options ...

find . \( -name '*.jpg' -o -name '*.jpeg' \) -print0 \
| xargs -0 -I % cp % dir


- parv

--
Email address is broken.

Re: Copying a bunch of images to one directory.

am 27.11.2007 14:47:26 von Geoff Clare

parv wrote:

>> find -name '*.jpg' -o -name '*.jpeg' | xargs cp --target-directory=/tmp/myporn
>
> That find(1)s only the files with suffix of 'jpeg' here on FreeBSD
> (6-STABLE).

Really? If true, that's a bug in FreeBSD's find.

With an explicit -print (or -print0) on the end, you would only get
the "*.jpeg" matches:

find . -name '*.jpg' -o -name '*.jpeg' -print # wrong!

but with no action specified, the implicit -print should apply to both.
POSIX says:

... if the given expression does not contain any of the primaries
-exec, -ok, or -print, the given expression shall be effectively
replaced by:

( given_expression ) -print

Of course, implementations that support the non-standard -print0 primary
also include it in the list of primaries that suppress the implicit -print.

--
Geoff Clare

Re: Copying a bunch of images to one directory.

am 28.11.2007 09:43:09 von parv

in message ,
wrote Geoff Clare ...

> parv wrote:
>
>>> find -name '*.jpg' -o -name '*.jpeg' | xargs cp --target-directory=/tmp/myporn
>>
>> That find(1)s only the files with suffix of 'jpeg' here on FreeBSD
>> (6-STABLE).
>
> Really? If true, that's a bug in FreeBSD's find.
>
> With an explicit -print (or -print0) on the end, you would only get
> the "*.jpeg" matches:
>
> find . -name '*.jpg' -o -name '*.jpeg' -print # wrong!
>
> but with no action specified, the implicit -print should apply to both.

Sorry, I was immensly wrong. What you state above is how actually
things work on FreeBSD too. Thanks much for the correction.


- parv


> POSIX says:
>
> ... if the given expression does not contain any of the primaries
> -exec, -ok, or -print, the given expression shall be effectively
> replaced by:
>
> ( given_expression ) -print
>
> Of course, implementations that support the non-standard -print0 primary
> also include it in the list of primaries that suppress the implicit -print.
>

--