Is there a simple command line program to check whether a particular folder exists, and if yes, make another folder in that folder?
Asked
Active
Viewed 122 times
2 Answers
0
I'd just try to create the folder as a subfolder.
If that fails because the outer folder does not exist, we have the desired behaviour, and all we need to do is ignore the error.

Simon Richter
- 28,572
- 1
- 42
- 64
0
if exist C:\Temp\ mkdir C:\Temp\1
m0Re "advanced" way:
@echo off
set root=C:\temp
set new=\NewFolder
if exist %root% goto L2
goto L3
:L2
if not exist %root%%new% mkdir %root%%new%
:L3

Zam
- 2,880
- 1
- 18
- 33
-
-
-
1I tried to modify your code a bit. actually I want to create folder by the name of year. Then check if folder exists in this folder by the name of month, if not create it. Then create a folder of today's date and then copy backup files in it. For Example \2014\Feb\18. @echo off set year=%year% set month = %month% set dd=%date% if exist %year%\%month% goto L2 goto L3 :L2 if not exist %year%\%month% mkdir %root%%new%%dd% :L3 – vrun Feb 18 '14 at 12:45
-
-
i am also using batch files for archive log files, create backups, and store it in %date% folder on few different drives... – Zam Feb 18 '14 at 13:00
-
I tried that already. I want it as \Year\Month\date. md %date% will create folder by today's date – vrun Feb 18 '14 at 13:07
-
check this: http://stackoverflow.com/questions/1192476/windows-batch-script-format-date-and-time and this http://stackoverflow.com/questions/14810544/get-date-in-yyyymmdd-format-in-windows-batch-file – Zam Feb 18 '14 at 13:22
-