I have written a simple script, to copy some files, and change there name:
#!/bin/bash
for directory in ./../old_files/*; do
DIR_NAME=$(basename $directory)
for file in $directory/*; do
filename=$(basename -- "$file")
cp -- $file "./${DIR_NAME}_m*${filename}" 1>/dev/null
done
done
And it's working great with one problem. If file has an accent or name is escaped with slash, it returns:
cp: target 'xxx.pdf' is not a directory
Any ideas how to solve this?
DIR_NAME
could potentially be set to a non-directory file, your*
in the cp command is going to be taken literally. – jesse_b Jun 29 '19 at 16:37directory
contains whitespace your script will break. – jesse_b Jun 29 '19 at 16:43