How to flatten a directory on Mac through terminal

Recently, I was handed a project with pre-built ANT scripts that zip folders up into individual directories. The zip files in each folder needed to be uploaded to an FTP site without the folder so having to navigate into each was a bit annoying and time consuming for 40 files.

If you find yourself in need of merge or flatten a folder/directory, use this snippet to flatten everything into a single directory. If a file exists with the same name, you’ll be prompted to overwrite or leave in the existing folder.

In my case, there was an extra file generated within each folder that was not used and I didn’t want to be prompted 40 times to overwrite so changing the -i to -n will force files to be overwritten. I’d recommend using caution with this and only use it when you know the duplicate files don’t matter.

 


There are no comments.

Leave a Reply