Sponsored Link

Wednesday, September 7, 2011

Windows batch script to create directory name DDMMYYYY

Many times I had to create directories with date as name for different purposes. I made this batch script to make that task easy. This is handy to keep all work of a particular day in its own folder. The following batch script will create directory of name format DDMMYYYY in the current path.

:: Auto directory date batch (MMDDYYYY format)
:: First parses month, day, and year into mm , dd, yyyy formats and then combines to be DDMMYYYY
:: Setups %date% variable
:: @author Deepu Mohan Puthrote www.deepumohan.com
@echo off
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%dd%%mm%%yyyy%
echo New folder name %date%
MKDIR %date%

Copy and paste this code into a file with extension bat and save it into a path where you want to create the directory. Double click on the batch file to create the current day's directory.

You can also download the batch file from here. You can safely download it, it is hosted in safe server of HostGator.
In the next post I will post the batch script for creating directory names with DDMONYYYY format. It will be pretty advanced which uses temporary javascipt and batch file. See the post here.

For those who are new to windows batch files, visit this site by Microsoft. You can also get these very good books from Amazon.com.

   
Related Posts Plugin for WordPress, Blogger...