Automate directory structure

I find myself making the same folders and files over and over again, and it would be nice if I could automate some of this.

I use templatr and hot keys to create a new file with a template, but as far I can tell, it can’t create folders.

Here is a rough example.
Case Folder
-case notes.md
-documents
–correspondence
–receipts
-recordings

Is there some solution that would allow me to do this in a more automated manner?

2 Likes

Script it…

mkdir case_name
cd case_name
touch 'case notes.md'
mkdir documents
mkdir correspondence
mkdir receipts
mkdir recordings 

Running the script will create the folders and files you need.

The script can be run on your command line or with the right plugin from within Obsidian.

It is possible to run system commands from a template to do this at the press of a keyboard shortcut!

Read over my post on running any command… but modify this process to run the above commands (to create folders and files).

https://medium.com/@gareth.stretton/obsidian-do-almost-anything-really-with-system-commands-b496ffd0679c

2 Likes

I thought about something like that, but was hoping something more native would be possible. It’s worth a shot.

I’m only a hobbyist programmer, but did take a look at the templatr docs, don’t know much of anything about javascript, but I didn’t see anything that allowed directories to be created.

It’s there, but it’s kind of indirect. If you either move or create files to new directories, they automatically appear.

1 Like

@holroy That’s pretty cool! If you could, it would be very helpful to see an example Templater script that did this for even a simplified version of the above use case. Thanks!

In this thread, Dynamic folder creation from a template - #2 by holroy, every new file was moved into a not one, but two deep new folder structure, based on the hour and minute of the current hour. Maybe not the most practical example, but it shows one way of creating folders using the move command. :smile:

In your case you might want to create new files in the given directories (, or slightly less elegant you could move one file around creating directories as the file bounces around… :wink: )

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.