Creating a new or blank folder structure from a text file

While cleaning up and organizing my drives, I ran into a situation where I wanted to replicate a folder structure, but not copy any of the files. I'm going to move the files to a new location, but want to keep working and not wait for the folders to copy. Turns out there are a couple of easy ways to accomplish this.

For the first method, create the directory structure you want using a plain text editor. This would be done by creating the path to lowest level folder you may need. You don't need to list all the interim directories.

If I were to list:

"Game Folder/Assets/Icons" it would make all three folders. If the folder name contains spaces, enclose the entire line in quotes. This is a great way to create the same folder structure over an over again for something like a website or coding project.

Next, open Terminal, switch to the new Parent folder where you want to create everything and type:

cat myfolderstructure.txt | xargs mkdir -p

Each folder in the text file will be created at the current location. If you get an errant "?" at the end of your folder name, make sure to save the file as plain text as this usually means a CRLF at the end of the line.

If you already have the folder structure created and want to replicate it, from one drive to another let's say, you can use rsync.

rsync -a /path/from/ /path/to/ --include \*/ --exclude \* [1]
rsync -av -f"+ */" -f"- *" /path/to/src /path/to/dest/ [2]

This may take a few seconds to process, but at the end, you will have a duplicate of your folder structure without any of the files. Very nice if you already have a working model you want to keep using.

Finally, there is a UI way of doing this. Post Haste for Mac, by Digital Rebellion offers a UI way of creating projects and templates. It offers a lot of features including the use of variables to define locations and dragging a folder list onto the window, which it will then replicate.

I just used the command line way to get started, but I think I will start using Post Haste moving forward. I can use it to define coding projects, download folders, and document structures without having to keep track of text files and jumping to the command line.

Best of all, Post Haste is free.

So, there are 3 solid options of creating a new folder structure, from a text file, or from an existing directory without having to type in all the folder names manually. Pretty nice!


Handcrafted with care just for you.

Author Signature for Posts