我一直在谷歌上搜索如何将文件扩展名插入到多个没有扩展名的文件(文件名到 filename.txt),以及更正错误的扩展名(例如,从错误保存的 .txt 到 .jpg),以及从此重命名过程中排除其他文件/文件夹。
我特别偶然发现的一页与我的非常相似:http ://ubuntuforums.org/showthread.php?t=1185203
在该线程的第二页上,有一个由 tinge 发布的脚本,这似乎是我正在寻找的解决方案(有人可以验证吗?):
#!/bin/bash
program () {
FILETYPE="$1"
# Select all files in current directory, and process one at a time
for FILE in *; do
# Strip of any extension, and save to FILE1
FILE1=${FILE%\.*}
# If it's the same afterward, then there was no extension - rename it
if [ "$FILE1" = "$FILE" ]; then
while [ -f "${FILE1}.${FILETYPE}" ] ; do
FILE1="${FILE1}_1"
done
mv "$FILE" "$FILE1.$FILETYPE"
fi
done
exit 0
}
case $1 in
--help) echo;echo;echo "Usage: noext.sh filetype i.e. noext.sh JPG changes all files with no extension to a .JPG";echo;echo;echo
;;
-h) echo;echo;echo "Usage: noext.sh filetype i.e. noext.sh JPG changes all files with no extension to a .JPG";echo;echo;echo
;;
*) program $1
;;
esac
我不确定它是否正确复制(我试图遵循 4 空格缩进规则。我想我把它砍掉了,哈哈),但它在我发布的线程链接的第二页上。由于不熟悉脚本,我不知道如何处理它。
我正在使用 Windows 7。
有人可以帮忙吗?
谢谢,-B