Score:0

Count files and do something with it (using JHead in my case)

us flag

I have a folder with files 1.JPG, 2.JPG, ..., 12.JPG

Is there an expression to process all the files at once? I want to use a JHead command, but I think there is a general solution.

Thank you!

Score:1
br flag

If the processing you require is something like renaming 1.JPG to MyPicture1-320x480.jpg, and 2.JPG to MyPicture2-320x480.jpg, etc. then if you are using the Bash shell, you could change to the directory that contains the files and use something like:

i=0; for n in *.JPG; do mv "${n}" "MyPicture${n/.JPG/-320x480.jpg}"; i=$((i+1)); done; echo "Processed ${i} files."

(The above can all be typed on one command-line.)

Or if you want to put it into a script, it would be easier to read and understand on multiple lines:

# reset counter variable if you want to count the number of files processed
i=0

# loop for all files in current working directory that end with ".JPG"
for n in *.JPG
do
  # rename (move) each file from the original name (${n} is generally safer than $n)
  # to a new name with some text before the original name and then with the end of
  # the original name (".JPG") replaced with a new ending
  mv "${n}" "MyPicture${n/.JPG/-320x480.jpg}"

  # increment the counter variable
  i=$((i+1))
done
# display the number of files processed.
echo "Processed ${i} files."

If the processing you want is different to this, you might need to edit your question to provide more details.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.