G'day
I am trying to get a script working that will copy existing files (most do no have an extension) to another folder and append all files with the extension .txt
I have the cp command down pat (cp /existing_folder /new_folder)
however I am stuck on the rename part. I have had some help with suggestions in getting some scripting down in order to rename files that dont have extension and move them to another folder (code below)
Code:
SOURCE_DIR="/home/webstuff"
TARGET_DIR="/home/webstuff/trial"
for SF in $SOURCE_DIR/*
do
case `basename "$SF"` in
*.* )
# Has an extension
TF=$SF
;;
* )
# Does not have an extension
TF="$SF.txt"
;;
esac
cp $SOURCE_DIR/$SF $TARGET_DIR/$TF
if [[ $? -eq 0 ]]; then
echo "Successfully copied $SOURCE_DIR/$SF to $TARGET_DIR/$TF"
else
echo "$? : Error occured coping $SOURCE_DIR/$SF to $TARGET_DIR/$TF"
fi
done
however it is spitting out the following:
Quote:
cp: cannot stat `/home/webstuff//home/webstuff/setMonDate': No such file or directory
1 : Error occured coping /home/webstuff//home/webstuff/weboutput to /home/webstuff/trial//home/webstuff/weboutput.txt
|
To me this is a problem with the copying of the files? Maybe a double copy??
The files do exist in the SOURCE_DIR="/home/irlp/webstuff" dir
I am seeking suggestions in getting the bash script working (Debian System)
Most files do not have an extension (they are scripts) and some do (eg .conf)
I am hoping to copy the files to a specific folder, append them with .txt and make them viewable for other on the web.
Hope that makes sense and I appreciate your input