Support multiple (two) directories.
Original file modification date is kept.
Old files are kept as well.
—
-
-
#!/bin/bash
-
-
dir1=a
-
dir2=bbb
-
resdir=results
-
-
# Save file name separator
-
OLDIFS=$IFS
-
IFS=$'\n'
-
-
# File rename by date
-
echo "Start first processing…"
-
for fl in $(find "$dir1" "$dir2" -type f); do
-
echo " * processing 1: $fl"
-
dirpostfix=a
-
if [ $(dirname "$fl") == "$dir2" ]; then
-
dirpostfix=b
-
fi
-
-
newfileBase=$(basename "$fl")
-
newfile=$(stat -f '%Sm' -t "%Y%m%d%H%M.%S_${dirpostfix}_${newfileBase}" "$fl")
-
cp "$fl" "$resdir"/"$newfile"
-
done
-
ls -alh "$resdir/"
-
-
# Process created files
-
echo ""
-
echo "Start second processing…"
-
pushd "$resdir"
-
i=1
-
for fl in $(ls); do
-
echo " * processing 2: $fl"
-
-
fts=$(echo $fl | cut -c3-15)
-
newfile=$(seq -f "%03g" $i $i)"_"${fl:16}
-
-
mv "$fl" "$newfile"
-
touch -t "$fts" "$newfile"
-
-
i=$(expr $i + 1)
-
done
-
popd
-
-
# Restore file name separator
-
IFS=$OLDIFS
-
-
ls -alh "$resdir"
-
-
echo ""
-
echo "Done! Enjoy
"
-
echo ""
—