
我有一個包含文件 1.JPG、2.JPG、...、12.JPG 的資料夾
有沒有一個表達式可以一次處理所有檔案?我想使用 JHead 命令,但我認為有一個通用的解決方案。
謝謝你!
答案1
如果您需要的處理類似於將 1.JPG 重新命名為 MyPicture1-320x480.jpg,將 2.JPG 重新命名為 MyPicture2-320x480.jpg 等,那麼如果您使用的是 Bash shell,則可以更改為包含文件並使用類似的東西:
i=0; for n in *.JPG; do mv "${n}" "MyPicture${n/.JPG/-320x480.jpg}"; i=$((i+1)); done; echo "Processed ${i} files."
(以上內容均可在一個命令列中輸入。)
或者,如果您想將其放入腳本中,多行會更容易閱讀和理解:
# 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."
如果您想要的處理與此不同,您可能需要編輯您的問題以提供更多詳細資訊。