find . -type f -exec cp {} <output folder> \;
Thank you!
Unfortunately, some of the files in these subfolders have the same name. Is there any way to make it so command line renames the files with the same names as a copy? Like someFile.jpg ---> someFile-1.jpg… or something of the sorts.
Since I'm working with thousands of files, it would be silly to manually scan through all of them and rename them...
Thank you!
Unfortunately, some of the files in these subfolders have the same name. Is there any way to make it so command line renames the files with the same names as a copy? Like someFile.jpg ---> someFile-1.jpg… or something of the sorts.
Since I'm working with thousands of files, it would be silly to manually scan through all of them and rename them...
Thanks in anticipation!
#!/bin/bash
if [ -z $1 ]; then
echo "Please provide an output folder"
exit 0
fi
OUTPUT=$1
if [ ! -e $1 ]; then
echo "Making output folder"
mkdir $1
fi
function renameAndCopyFile() {
f=`basename $1`
COUNT=1 # Start with 1
while [ 1 ]; do
fname=`echo $f | cut -d '.' -f1`
ext=`echo $f | cut -d '.' -f2`
o="$fname-$COUNT.txt"
if [ -e $OUTPUT/$o ]; then
COUNT=$((COUNT+1))
else
echo "Rename and Copying $1 as $o"
cp $1 $OUTPUT/$o
break
fi
done
}
# Begin of main script
for file in `find . -type f`; do
if [ -e $OUTPUT/`basename $file` ]; then
echo "File exists"
renameAndCopyFile $file
else
echo "Copying $file..."
cp $file $OUTPUT;
fi;
done