Optimize .BAT to create dir's/sub-dir's & log

August 23, 2011 at 11:04:49
Specs: Windows XP
I have a .BAT that accepts a user input for a site code which then traverses through a FTP server and creates dir's and sub-dir's. I wanted to see if this logic could be optimized and if it could log successful/unsuccessful dir creation. (this is a .BAT but I was thinking to do in .VBS (for an interactive HTA) if anyone has suggestions)


CODE BELOW
@echo off

SET /P site=What is the 4 character site code you wish to add[ie-ABCD]?:
IF "%site:~4,1%" neq "" echo You entered a site code that was too long and the application will quit now && PAUSE && goto :eof
IF "%site:~3,1%" equ "" echo You entered a site code that was too short and the application will quit now && PAUSE && goto :eof
ECHO %site% | findstr /R /C:[A-Z][A-Z][A-Z][A-Z] > nul
IF ErrorLevel 1 (
ECHO ERROR:"%site%" Your entry does meet the site code standard and the application will quit now && PAUSE && goto :eof
)

PUSHD A:

::Create the root site code dir
CD\
MKDIR %site%

::Change path into the newly created site code dir to create sub-dir's
CD %site%
MKDIR FILETYPE1
MKDIR FILETYPE2
MKDIR FILETYPE3
MKDIR FILETYPE4
MKDIR TEST

:: Now create (sub)sub-dir's based on the site code within the newly created sub-dir's
CD\
CD A:\%site%\FILETYPE1
MKDIR %site%
CD\
CD A:\%site%\FILETYPE2
MKDIR %site%
CD\
CD A:\%site%\FILETYPE3
MKDIR %site%
CD\
CD A:\%site%\FILETYPE4
MKDIR %site%

::Create addtl sub-dir's in the TEST dir within
CD\
CD A:\%site%\TEST
MKDIR FILETYPE1
MKDIR FILETYPE2
MKDIR FILETYPE3
MKDIR FILETYPE4

ENDLOCAL



See More: Optimize .BAT to create dirs/sub-dirs & log

Report •


#1
August 23, 2011 at 16:19:39
You can do something like this:
MKDIR (FOLDERHERE) > MKDIR.LOG

It will make a log in the folder the batch file is in. You can open the log just with notepad. Does this help?

Mouse could not be found. Click OK to continue.
What to do now?


Report •
Related Solutions


Ask Question