Windows batch script to create directory auto file name DDMONYYYY with the help of javascript
In the previous post I had shown a windows batch script for creating directories with name of format DDMMYYYY. In this post I will show you how to create directories of format DDMONYYYY. I did a lot of research on web to figure this out. Here is the script, it looks a little bit complex.
|
|
Copy and paste this code into a file with extension bat and save it into a path where you want to create the directory. Please do share your comments.
You can also download the batch file from here. You can safely download it, it is hosted is safe server of HostGator.
The above script creates a tempDate.js and tempDate.bat file. Windows can run javascript file using the command cscript. Output of this javascript file is taken to tmpDate.bat file.
A sample javascript file generated by the above code is given below.
|
|
As you can see a javascript array is created that holds index for each month. Next we create a new Date object using javascript function new Date()
. From the date object get the date, month and year. Next we get the MON format of month from the javascript array already created. Now in date
variable we have the date in the required format. WScript.Echo()
command will give the output. And the output will be mkdir DDMONYYYY. This output is taken into the tmpDate.bat file. Then the tmpDate.js file is deleted and tmpDate.bat file is executed using the call command.
In the next post I shall give an improved version.
For those who are new to windows batch files, visit this site by Microsoft.
Author: Deepu Mohan Puthrote
Link: https://deepumohan.com/tech/windows-batch-script-to-create_07/
This work by Deepu Mohan Puthrote is licensed under a Creative Commons Attribution 4.0 International License