PDA

View Full Version : [SOLVED] how to move files from subfolders to the main?



paker
August 19th, 2009, 03:23 AM
I have a folder with sub, sub-sub, and sub-sub-sub folders. I want to completely eliminate the folder structure and put all files in the main. Is there an easy way to do this? Thanks.

Baneblade
August 19th, 2009, 03:27 AM
Cut and Paste?
Failing that, perhaps a custom script to "mv" the files?

kaibob
August 19th, 2009, 03:52 AM
The following will copy all files from the source directory and subdirectories to the destination directory:


find /source/directory -type f -exec cp '{}' /destination/directory ';'

You indicate that you want to "put all files in the main." The meaning of this is not clear to me, and its meaning may determine the method used to delete the directory structure.

paker
August 19th, 2009, 04:56 AM
Thank you. That will do. Once files are moved to the main directory from all subdirectories, file conversion operation becomes much easier. Thanks.

paker
August 19th, 2009, 07:44 PM
Thank you. It worked. When I did Right Click > Properties, the destination had 5000 'items' whereas the source had 5100 'items'. I thought some files got dropped. I just didn't know each folder is counted as 'item.' Thanks.

kaibob
August 20th, 2009, 02:41 AM
Thank you. It worked. When I did Right Click > Properties, the destination had 5000 'items' whereas the source had 5100 'items'. I thought some files got dropped. I just didn't know each folder is counted as 'item.' Thanks.
It's possible that files in different subdirectories had identical names and that some copied files overwrote others. The command could be rewritten as a shell script to check for this and to append a number in the case of duplicates. I seem to recall someone doing this as a one-liner, but I can't find it now.