ファイルを数えて何かする(私の場合は JHead を使用)

ファイルを数えて何かする(私の場合は JHead を使用)

1.JPG、2.JPG、...、12.JPGのファイルを含むフォルダがあります

すべてのファイルを一度に処理する式はありますか? JHead コマンドを使用したいのですが、一般的な解決策があると思います。

ありがとう!

答え1

必要な処理が、1.JPG を MyPicture1-320x480.jpg に、2.JPG を MyPicture2-320x480.jpg に名前変更するなどの場合、Bash シェルを使用している場合は、ファイルが含まれているディレクトリに変更して、次のようなコマンドを使用できます。

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

(上記はすべて 1 つのコマンドラインで入力できます。)

または、スクリプトに記述する場合は、複数行に記述した方が読みやすく理解しやすくなります。

# 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."

必要な処理がこれと異なる場合は、質問を編集して詳細を追加する必要があります。

関連情報