Project Folder Batch Script



I have a specific way of organising my project folders. I like to have folder name, then a cache folder, footage folder, renders folder... and in the renders folder, a passes folder... but I hate having to create these folders EVERY SINGLE TIME I work on a new project/shot.

In this tip, I'll show you how to use a Windows Batch scripting to automatically create all these folders for you.

Creating a batch script in Windows is extremely simple. All you need is a basic understanding of Command Prompt, an understanding you can gain in less than a minute!


Writing batch scripts in Win was made fairly easy. The scripts basically execute commands in the prompt as if you were typing them yourself.
If you're not interested in scripting, you can scroll to the bottom and grab the final code.

For example, if you had a batch script like this:


dir/a:h
attrib Users -s -h -r


This would apply those commands in that order. For the moment, they would execute regardless of whether the previous code was successful or not. You could add extra functionality, but this is not a lesson on scripting, it's about creating a project folder script.

This process will take a few minutes, a worthy cost for what this is going to do for you.


Draw a Heirachy


It's good to plan how you're going to do this. So plan the heirachy in your directories. I have it this way:

Cool! So I have it all figured out, now I need a script that will automatically make all these folders for me. So...


The Batch Script


Open up Notepad. This is where all the coding will happen.
Write "set" and then save the file. Make sure to set "Type" to "All Files" then the filename to "MyScript.bat". Save it anywhere.

I took the time to write out the code. The specific commands are defined clearly after:


set foldername=Project_ONE


md %foldername%
cd %foldername%


md cache
cd cache
md proxies
cd..


md footage
cd footage
md img seq
cd..


md preview
md projectfiles
md references


md renders
cd renders
md passes
cd..




Okay okay! What the heck is all this?
set foldername= Set lets you define a variable. A variable is a code the script refers to keep from repetitiveness. After the equals sign is the name of the project folder. This is the only part of the entire script that you'd change when creating further project folders.

%foldername% This is a reference to the "set" that we used above. Using this allows the folder name to change without us having to change too many lines of code when we're making new folders again. If not for set and this string, we'd have to change 3 parts of the code, rather than one.

md md stands for "make directory", it basically creates a folder with the name that follows.

cd cd lets us open or enter a directory. So if at first we were in C:\Users\, then typing cd Guest would take us to C:\Users\Guest\, so we'll be creating folders and so on inside THAT folder.

cd.. This moves us out of the directory by 1 step. In the above example, typing it would take us back up to the "Users" directory/folder.


Notice that whenever I used cd to enter a folder, I used cd.. to pull out again to continue making more folders. I grouped stuff together so in the future, I can come in and easily know what's going on.



Make it Look Cool


So we're done with that. That's the main code, now it's time to make it user friendly.
We'll change the color of the interface, add a fancy title and add some visual to ensure everything's going as planned.

At the top, just after the set, we'll add this code::

echo off
title Project Folder Creator
color f0
cls
echo Welcome to Project Folder Creator.
echo Will create the following folder:
echo %foldername%
echo If this is okay,
pause
cls



echo is what the cmd writes. by typing echo off, we're switching off the way it constantly shows C:\Users\>. This hides what it's doing behind the scenes.
In the next instances of echo, it's used to show the words only. This works great to notify the user what's going on. Notice we're using %foldername% again. This is so that before the rest of the script runs, the user is reminded the name of the folder that's about to be created. Useful.

title lets us change the name of the window. Just for fun.

color f0 this command changes the color of the interface to Bright White background and white text. To find out the other colors available, start command prompt (search in start or Run "cmd") and type color/?

cls Classic command. Used to clear the screen. This removes the echo off and color change commands we wrote. User doesn't need to see that.

pause At that point, cmd will bring up a "Press any key to continue..." section. This gives us time to read the echoes we wrote above.

Cool!

We need to add feedback at the end of the batch. So, we'll add this to the bottom of the code:

cls
cd..
start %foldername%
cd %foldername%
echo Batch Complete!
tree
pause


We've used cls again. The cd... lets us pull out of foldername so we can actually start it, and then went back in so the tree command can work.

start This basically opens the folder we created.
tree will show a tree diagram of the folders created. Useful to view if everything went well. If it didn't, we can tell.
If the code didn't work (like at md or cd), the batch would still continue running. So that's why we echo "Batch Complete", but not "Operation Successful", because we haven't confirmed that it works. That's why we use a tree at the end, so the user can see what happening :-D


Final Code





echo off
title Project Folder Creator
color f0
cls
echo Welcome to Project Folder Creator.
echo Will create the following folder:
echo %foldername%
echo If this is okay,
pause
cls

set foldername=Project_ONE


md %foldername%
cd %foldername%


md cache
cd cache
md proxies
cd..


md footage
cd footage
md img seq
cd..


md preview
md projectfiles
md references
md renders
cd renders
md passes
cd..



cls
cd..
start %foldername%
cd %foldername%
echo Batch Complete!
tree
pause


Add some copyright information, some fancy text-art with echo, and we're done!

See the title! After pressing Enter:




Using it


So save and copy the .bat file to the folder where you want the project folder to appear. Right-click and choose "Edit" to change the name of the foldername, hit save, then run the batch. It may seem like a process, but it sure as heck is faster than creating these folders yourself.

Personally, I removed the "start" and the final pause and tree. Since I know it works, I don't need them.
Feel free to tweak the code!


Building More


If you'd like to learn more commands you can use, open Command Prompt and type help, this will list all commands. Then, you can type help followed by the command to show more information on that specific command. Handy!
Enjoy! :-D