我有以下脚本来摆脱FAT32系统不喜欢的字符:
bad_chars="\?:\|\"*"
F=`find . | grep [$bad_chars] | head -n1`
while [ "$F" != "" ]
do
new_F=`echo $F` | sed s/[$bad_chars]/_/g`
mv "$F" "$new_F"
F=`find . | grep [$bad_chars] | head -n1`
done
现在它卡在有问号的文件上,它出现了错误
mv: rename ./[FILE_PATH]/What? _.pdf to ./[FILE_PATH]/What_ _.pdf: No such file or directory.
它不会对带有问号的所有文件执行此操作,我尝试添加虚拟?.txt
文件并且处理得很好。在同一路径中还有其他pdf,但名称不相似。
答案 0 :(得分:1)
我认为脚本可以简化一点:
#!/bin/bash
shopt -s globstar # enable recursive expansion with **
shopt -s nullglob # expand to nothing if no files match the pattern
bad_chars="\?:\|\"*"
for i in **/*["$bad_chars"]*; do
mv "$i" "${i//[$bad_chars]/}"
done