Question

I currently have a set of folders that I need to duplicate the structure into another folder.

I currently work with photos that are dumped into a Dump folder in groups. Eg.

Photo Dump Group1 Group2 etc

I would like to have a script to recreate these folders without the files to the good folder so that I don't have to recreate them manually

Any ideas?

Nathan

Was it helpful?

Solution

If I understand correctly, you want to copy the parent folder and all of its subfolders, but none of the files contained therein. There might be a simpler way, but I just threw together this Terminal command (which should also work on Linux or anywhere else with Bash):

ls -R | grep :$ | sed 's/\.\/\(.*\):$/\1/' | \
while read thisFolder; do mkdir -p "destination"/"$thisFolder"; done

It will copy the folder structure of all folders in the current directory into a folder called "destination"; you can of course change this to any path you wish, e.g. ~/Desktop/"Folder Copies" or whatever.

Take care to first "cd" into whatever directory contains the folder tree you want to duplicate, because if you run it as soon as you open the terminal, you'll wind up with a replication of your entire home folder directory structure, including the many contained within Library.

OTHER TIPS

I found this to be a tad clearer:

find 'Photo Dump' -type d | sed -e 's:^Photo Dump:destination:g' | sort | xargs mkdir
  • find 'Photo Dump' -type d -> List all folders in "Photo Dump"

  • sed -e 's:^Photo Dump:destination:g' - Since all folders listed in the above step will start with Photo Dump/..., we can just replace the beginning with the folder we want to copy the structure to (in this case I called it destination)

  • sort - Sorts results. This is required so that the parent folders are created before the children

  • xargs mkdir - Passes all the results from above into mkdir so it can create the folders

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top