for imageFolder in *; do
[ -d $imageFolder ] && cd "$imageFolder" &&
for file in *.*
do
echo "$file" #"${file/?/?}" //the bit I am stuck on I believe.
done
done
#!/bin/bash
shopt -s nullglob
for imageFolder in */; do
cd "$imageFolder" || continue
n=1
for file in *.*; do
echo mv -- "$file" "$((n++)).${file##*.}"
done
cd -
done
或(带有子外壳)
#!/bin/bash
shopt -s nullglob
for imageFolder in */; do
(
cd "$imageFolder" || exit
n=1
for file in *.*; do
echo mv -- "$file" "$((n++)).${file##*.}"
done
)
done
我不相信您会找到
${file/?/?}
产生数字序列的参数替换 - 特别是不是每个文件夹的数字序列。相反,您将需要设置和增加一个变量。什么参数替换(特别是,
${file##*.}
)将用于提取文件扩展名,以便您可以将其重新添加到顺序文件名中。因此,例如,您可以这样做:或(带有子外壳)