Saturday 25 July 2015

Window batch file created folder in current date and copy files.

Windows batch file creating folder in current date as name.

In following example contains the concept for 

1.substring  in batch file
2.comments in batch file
3.creating the folder 
4.for loop 

substring in batch

SET yy=%date:~-4%
 my date is "Sat 07/25/2015 " by using the above code i have cut the "2015" only

Comments
By using  :: i did comments Ref line no 2 author 

my system date format is Sat 07/25/2015  By using substring i have convert into dd-mm-yy

Instruction: Do leave the space between variable declaration and initializing eg. Ref: line no 5-10


@ECHO off
::author bala2e
SET appName=bala2e

SET yy=%date:~-4%
SET mm=%date:~-10,2%
SET dd=%date:~-7,2%
SET MYDATE=%dd%-%mm%-%yy%
SET baseDir=\\192.168.10.88\home\%MYDATE%
SET serverDir=\\192.168.8.202\eGurkha\manager\tomcat\webapps\final
SET appBaseDir=%baseDir%\%appName%
SET controllerDir=%appBaseDir%\controller
SET viewDir=%appBaseDir%\view
SET mkDirectory=(%baseDir% %appBaseDir% %controllerDir% %viewDir%)

FOR %%i IN %mkDirectory% DO MKDIR %%i
SET FILE_LIST=(%serverDir%\reporter\file.jsp %serverDir%\WEB-INF\classes\com\reporter\file.java %serverDir%\WEB-INF\classes\com\db\MsSqlConnect.java %serverDir%\WEB-INF\classes\com\db\OracleConnect.java)

FOR %%i IN %FILE_LIST% DO COPY %%i %baseDir%


COPY "%serverDir%\reporter\scripts\%appName%\*.*" %appBaseDir%
COPY "%serverDir%\reporter\scripts\%appName%\controller\*.*" %controllerDir%
COPY "%serverDir%\reporter\scripts\%appName%\view\*.*" %viewDir%

No comments:

Post a Comment