Re: adding leading zeros to a filename

From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 01/31/05


Date: Mon, 31 Jan 2005 09:25:45 +0000

2005-01-30, 22:15(+00), Chris F.A. Johnson:
[...]
> You can test before the loop:
>
> set -- *.jpg
> [ -f "$1" ] &&
> for file
> do
> : do whatever with "$file"
> done
[...]

what if:

mkdir 1.jpg
touch 2.jpg

?

> Or you can test within the loop:
>
> for file in *.jpg
> do
> [ -f "$file" ] || continue
> : do whatever with "$file"
> done
[...]

Better (as long as you require the files to be regular files or
symlinks to regular files which is likely to be the case for jpg
files).

-- 
Stéphane


Relevant Pages

  • Re: adding text to JPEGs, in bulk
    ... Not on the first loop - the *.jpg is evaluated before the loop runs. ... You will find an incomplete command (eg just the first ... series of small mistakes in order to avoid making unplanned large ...
    (Fedora)
  • RE: Create html pages w/ images and text
    ... > Volk) wrote: ... > about pictures whose basename is not in the loop. ... > txt and one for jpg, and test if the .html file exists yet. ... > EOI ...
    (perl.beginners)
  • Re: batch delete and rename files
    ... for file in *.jpg ## for each file enfing with .jpg ... ## remove leading zeroes, or the number will be read as octal, ... My code in this post is copyright 2004, Chris F.A. Johnson ...
    (comp.os.linux.misc)
  • Re: Save screen shot efficiently?
    ... The queue is used to signal the bottom loop to execute the screenshot ... One other thing which may help.  JPG is a poor format for ... small size, I would recommend GIF or PNG.  ... The file size will be large due to no compression, ...
    (comp.lang.labview)
  • Re: basic command pipe question
    ... Not pretty but that's roughly what I used to move a bunch of JPEGs ... with .jpg and .JPG extentions... ... One thing that would bite you on a for loop like this is files with ... Using xargs, you can use the -0 option to ...
    (Fedora)