AHK: How to Make a $hit Ton of Files in 60 Seconds

For future reference, I’m posting the code at the top. Details follow below.

STEP 1: Make a new AutoHotkey file. Don’t know what that is? Don’t worry. It’s real easy.  Click here.

STEP 2: Go into your C Drive. Make a folder called Folders1_200.

CDriveMakeFolder1

STEP 3: Right click your new AutoHotKey Script → Edit Script.

STEP 4: Copy and paste this text into the body.

varFolderNumber=1
Loop, 200
{
    FileCreateDir, C:\Folders1_200\%varFolderNumber%
    varFolderNumber++
}
return

STEP 5: Save the AutoHotkey script → Close → Right click the script → Run Script

STEP 6: Check your C drive Folders1_200. If everything went well, it should look like this.

allTheFiles

 

Anatomy of a Script:

The Awesome-Shit-Ton-of-Files-Making-Script (ASTOFMS for short) was a result of an odd work assignment a few weeks back. My boss asked me to make an ass load of folders numbered sequentially 1 to 200.

I knew there was an AutoHotkey command for making folders (FileCreateDir, theNameOfTheFile), so I convinced myself it’d be faster to type it into a script.

ASTOFMS Version 1 looked like this:

FileCreateDir, C:\Folders1_200\1
FileCreateDir, C:\Folders1_200\2
FileCreateDir, C:\Folders1_200\3
FileCreateDir, C:\Folders1_200\4

Because I am a dumbass. Don’t be like me.

After the fourth line, I stopped and silently asked myself why the hell I hadn’t spent more time in the planning stage of ASTOFMS. This was no faster than right-clicking to make the file and typing in numbers.

Now I’d heard of this thing called a LOOP. It’s a command that basically tells the computer to do something over and over again. Anytime you catch yourself doing something repetitive, there’s a good chance you could use one of these to do it for you.

In AutoHotkey, Loops look like this:

Loop, 200
{
Do this 200 times
}

Great, I thought, I can make a Loop that tells the computer to make a file 200 times. But how do I get it to name the files properly? They need to be labeled 1 to 200.

This is where variables come in. Variables store information for later use-like numbers and text. In AutoHotkey, these are assigned the same way it’s done in math class.

varFolderNumber=1

To use this variable in a line of code, surround the name in %’s. TASTOFMS starts with that variable at 1 because I want my first file to be called 1. So the first run of the LOOP would take

FileCreateDir, C:\Folders1_200\%varFolderNumber%

to mean

FileCreateDir, C:\Folders1_200\1

Here’s the great thing about variables. They can be redefined within a loop based on a formula. For instance, you can tell the loop to add one each time it runs. All you have to do is add ++ to the variable name at the end of the loop.

varFolderNumber++

If the loop is set to run 200 times, your variable will end up being 200.

Here’s the full code translated:

AnatomyOfShitTonOfFiles

 

Advertisements
Tagged , , , , , , ,
%d bloggers like this: