Batch script to Create folder with Timestamp

I have written a batch script this morning to set a standard for creating adhoc folders on servers; essential to keep things tidy and at one place.

@ECHO off
@ECHO *****************************************************************************
@ECHO Create Folder with TimeStamp Script
@ECHO Suleman Mohammed (SQL DBA)

Set Date=%date:~6,4%%date:~3,2%%date:~0,2%
Set Time=%time: =0%
Set Time=%time::=%
Set Time=%time:~0,6%

Set TimeStamp=%Date%_%Time%

set /p Initials=”Please enter your Initials : “

SET ToUpper=%Initials%
IF [%ToUpper%]==[] GOTO EndToUpper
SET ToUpper=%ToUpper:a=A%
SET ToUpper=%ToUpper:b=B%
SET ToUpper=%ToUpper:c=C%
SET ToUpper=%ToUpper:d=D%
SET ToUpper=%ToUpper:e=E%
SET ToUpper=%ToUpper:f=F%
SET ToUpper=%ToUpper:g=G%
SET ToUpper=%ToUpper:h=H%
SET ToUpper=%ToUpper:i=I%
SET ToUpper=%ToUpper:j=J%
SET ToUpper=%ToUpper:k=K%
SET ToUpper=%ToUpper:l=L%
SET ToUpper=%ToUpper:m=M%
SET ToUpper=%ToUpper:n=N%
SET ToUpper=%ToUpper:o=O%
SET ToUpper=%ToUpper:p=P%
SET ToUpper=%ToUpper:q=Q%
SET ToUpper=%ToUpper:r=R%
SET ToUpper=%ToUpper:s=S%
SET ToUpper=%ToUpper:t=T%
SET ToUpper=%ToUpper:u=U%
SET ToUpper=%ToUpper:v=V%
SET ToUpper=%ToUpper:w=W%
SET ToUpper=%ToUpper:x=X%
SET ToUpper=%ToUpper:y=Y%
SET ToUpper=%ToUpper:z=Z%

Set FolderName=%ToUpper%_%TimeStamp%
md %FolderName%

Save the above script as CreateFolder.bat and run it; This will prompt you for your initials and create a folder in this format ‘SM_20111223_091505’

This entry was posted in .bat scripts, Tricks, Windows and tagged . Bookmark the permalink.

Leave a Reply