If I understand what you need is a way to look within a folder, and all subfolders of that folder, and copy any files found into a different "destination" folder, without creating any subfolders in the "destination" folder.
So if you have a fileset like this:
folderA/file1
folderA/subfolderC/file2
folderA/subfolderC/subD/file3
folderA/subfolderC/subE/file4
folderB/subfolderF/file5
folderB/subfolderG/subH/file6
folderB/subfolderG/subI/file7
And you are copying the files to the folder "../destfolder"
. Then, after the files are copied, the "../destfolder"
will contain:
../destfolder/file1
../destfolder/file2
../destfolder/file3
../destfolder/file4
../destfolder/file5
../destfolder/file6
../destfolder/file7
and "../destfolder"
will contain none of the subfolders from "folderA"
or "folderB"
.
You do this by changing to the directory that you want to copy the files from, and then run this from the command prompt:
d="../destfolder";for f in $(find -type f -exec echo {} \;); do b=$(echo $f|sed -r 's!^.*/([^/]+)!\1!'); echo cp -p "$f" "$d/$b" ;done
Before you "run" this command, you will need to substitute your actual destination folder in place of "../destfolder"
This will display a list of cp
commands, but will not actually copy any files. It should look like this:
cp -p folderA/file1 ../destfolder/file1
cp -p folderA/subfolderC/file2 ../destfolder/file2
cp -p folderA/subfolderC/subD/file3 ../destfolder/file3
cp -p folderA/subfolderC/subE/file4 ../destfolder/file4
cp -p folderB/subfolderF/file5 ../destfolder/file5
cp -p folderB/subfolderG/subH/file6 ../destfolder/file6
cp -p folderB/subfolderG/subI/file7 ../destfolder/file7
Once you are confident the correct files will be copied, you can run the command again, but remove "echo"
from the part of the command that's like: "echo cp -p..."
So the command that will copy the files will look like:
d="../destfolder";for f in $(find -type f -exec echo {} \;); do b=$(echo $f|sed -r 's!^.*/([^/]+)!\1!'); cp -p "$f" "$d/$b" ;done
Remember that before you "run" this command, you will need to substitute your actual destination folder in place of "../destfolder"
If you want this as a shell script, it would look like this:
#!/bin/sh
d="../destfolder"
for f in $(find -type f -exec echo {} \;); do
b=$(echo $f|sed -r 's!^.*/([^/]+)!\1!')
echo cp -p "$f" "$d/$b"
done
If this is not exactly what you need, then let me know and I'll have another look at it.
-type f
flag to find (i.e.find ./ -type f
) and it will find ONLY files...that being said, how comfortable are you with shell scripts as this could be attained with one?find
with some other commands can yield you that result...if you're not comfortable with shell scripting then there might be other options