How to create a free folder locking batch file

There are several commercial folder locking products available on the market that can be used to password-protect a folder and keep other users away from your personal files. However, before you spend your hard earned money on such a product, it’s worth investigating the available built-in means of folder locking that might be already included with Windows. If you are familiar with batch files and how to create them you may find the following method of some use.

To begin, copy the following text and paste it into a blank Notepad document on your computer:

Make sure you’ve copied all text from the box above. One way to ensure that is to click within the box with the mouse and press Ctrl+A to select all text within the box, then press Ctrl+C to copy it. Now open a blank Notepad window, and press Ctrl+V to paste the text in it. Finally, save the newly created text as folderlocker.bat file. To do that, choose File – Save As from the menu of Notepad, enter folderlocker.bat as the File name, and before pressing the Save button, make sure that Save as type box has All files selected:

Save the folderlocker file as a .bat file

In our example, we saved the file into the Downloads folder, but you can save it to a different folder, just remember where to find this file later.

Now you need to customize the folderlocker file to make it fit your specific situation. First, you decide which folder you want to lock with which password, and write this information into the batch file you’ve just saved. To do that, right-click on the folderlocker file in Explorer and choose Edit from the menu, that should open it in Notepad again. Look at the top portion of the file that contains 3 lines beginning with set: those are the lines you need to change to adopt the file to your specific folder and password.

The first line should specify the folder where you want you secret folder to be located. In our example, we wanted the secret folder to be on the Desktop, so we entered:

set PARENT_FOLDER=%USERPROFILE%\Desktop

If you want it to be in some other folder, enter its path here. For example, if you have a flash drive that has the letter E:, you would specify it as:

set PARENT_FOLDER=E:

The second set line should specify the name of the folder you want to be locked. In our example, we wanted it to be named Secret, so that’s what we’ve entered:

set SECRET_FOLDER=Secret

If you have not created this folder yet, run Explorer, open the folder that you have specified as PARENT_FOLDER above, right-click on an empty space within that folder, choose New – Folder from the menu, and finally replace the New folder name with the name of your choosing such as Secret. If you’ve decided to name it differently, say Personal files, then modify the second line appropriately:

set SECRET_FOLDER=Personal files

The final modification that you need to do is supply the password that you want to use. Do it on the 3rd set line, such as:

set PASSWORD=test

This way you will need to enter test as the password when you locking or unlocking the folder. Of course, you are welcome to choose a different password.

Now save the batch file and give it a test: double click folderlocker in Explorer and see what happens:

Locking the folder C:\Users\User\Desktop\Secret
Enter your password or press Ctrl+C to exit:
>test
The folder has been locked.
Press any key to continue . . .

If you don’t see the above and the file appears in Notepad again, it means you did not save it as a batch (.bat) file: see above about selecting All files as the file type when saving the file. If you do see the command window with the text similar to the above, it means it’s working! Watch the Secret folder disappear from your desktop (or from a different parent folder, if you’ve changed it). Now run folderlocker again, enter your password, and you should see a command window with the result similar to this:

Unlocking the folder: C:\Users\User\Desktop\Secret
Enter your password or press Ctrl+C to exit:
>test
The folder has been unlocked.
Press any key to continue . . .

The Secret folder should be back now! That’s how our simple batch file works for locking and unlocking a folder with a password.

Before you go and celebrate the money you saved by not buying a commercial product that provides a real password protection, consider the following:

  • If someone else logs it to your computer, and they come across the folderlocker file, they can open it in Notepad (just like you did) and discover both the folder you want to be locked and the password you used to lock it. To minimize such a risk, you may want to move the folderlocker file to some obscure folder that is not easily stumbled upon by a casual user. Or, maybe you better purchase one of the commercial products, such as Folder Guard, that handles and hides the passwords properly.
  • If someone disables the Explorer option to hide the system files, the locked folder will become visible. You may need to make use of such an opportunity yourself, if for example you forget the password or misplace the folderlocker file. To do that, open Windows Settings and search for File Explorer options. What it opens, select the View tab, and deselect the option Hide protected operating system files:
Creare the HIde protected operating system files option to display the locked folder

Press OK and confirm that you do want to display the system files. (If you really don’t want that, you can enable this option back again later.) Now open the folder that you’ve previously specified on the set PARENT_FOLDER line, such as the Desktop folder. You should see a folder named Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}, that’s your secret folder! You (or someone else) can rename it back to what it used to be, no password would be required for that. If you don’t want that to happen, consider purchasing Folder Guard software: when it hides a folder, it remains hidden even if the File explorer option is cleared.

  • What if you want to have several different folders to be locked with different passwords? Our little batch file cannot handle that. What if instead of making the folder hidden you would rather make it write-protected, to prevent ransomware from taking y our files hostage? Again, this batch file can’t do that, but Folder Guard can.