Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

This is an IIS website deployment script I started to write. It moves files from directory A to directory B and creates a log file with the date/time as the file name. When it's run in the AM hours, the time part of the log file name gets truncated because of the spaces. How can I fix this so it works for all times during the day (ie: 00.00.01, 00.00.11, 00.01.11, 00.11.11, 01.11.11 and 11.11.11 to give you some examples)? If you like "9"s then use 9s. Truncation occurs when we have 0s in the file name.. I think it treats it as a space. It's been a few months since I looked at this, but more critical projects came up and I put this aside. We just schedule the deployments in the evening for now. Haha! Essentially I want to use the least amount of IF statements as possible--but if you have a ton, I don't really care. If you have anything in your arsenal, awesome! :-) The script uses a "." (not a ":") for the time delimiters since colons aren't allowed in file names. If you're stumped, just say "MacGruber!" and take a drink of your diet Pepsi.

Prerequisites:
- You need to have the UI.Web folder created already
- You need the Robocopy.exe file in the path it expects
- You need a "logs" folder made before running script

REM **************************************************************
REM * TITLE:   LIMS Deployment Script                            *
REM * AUTHOR:  MacGyver                                          *
REM * PURPOSE: Deployment Script for IIS Web Server Files        *
REM *          - include all files recursively                   *
REM *          - excluded folders: .svn/obj                      *
REM *          - excluded files:   *.config, *.vb, *.cs, *.resx, *
REM *            *.vbproj, *.user, *.suo, AND others             *
REM * ASSUMES: UI.Web folder already exists                      *
REM **************************************************************

SET ROBOCOPY=".\robocopy.exe"
SET SOURCEDIR="\\tsclient\C\Source\websitename\UI.Web"
SET TARGETDIR="D:\web\docs\UI.Web"

SET DYYYY=%date:~-4,4%
SET DMM=%date:~-10,2%
SET DDD=%date:~-7,2%

SET THH=%time:~0,2%
SET TMM=%time:~3,2%
SET TSS=%time:~6,2%

REM - copy from one folder to another - the time doesn't work if you deploy the code in the AM, we need to fix that
%ROBOCOPY% %TARGETDIR% %TARGETDIR%_%DYYYY%-%DMM%-%DDD%_%THH%.%TMM%.%TSS% /S

REM - modify original folder with deployment changes & log the changes to a *.log file
%ROBOCOPY% %SOURCEDIR% %TARGETDIR% *.* /S /NP /XO /XD .svn obj /XF *.config *.vb *.cs *.resx *.vbproj *.user *.resources *.user *.suo > .\logs\Deployed_%DYYYY%-%DMM%-%DDD%_%THH%.%TMM%.%TSS%.log

iisreset
share|improve this question
    
oh, and the target folder gets the date_time stamp in it. –  MacGyver Aug 4 '11 at 3:26

2 Answers 2

up vote 1 down vote accepted

I had to read your question a few times to understand it. I think you need to swap out the just your setting of the THH variable. Change:

SET THH=%time:~0,2%

to

FOR /F "tokens=1-3 delims=: " %%a IN ('TIME /t') DO SET THH=%%a

If it cuts out the full two digits for the minutes, you can swap out your TMM for

FOR /F "tokens=1-3 delims=: " %%a IN ('TIME /t') DO SET TMM=%%b
share|improve this answer
    
Been meaning to test both of these answers for the past few weeks, but our server that I deploy to is 1 hour ahead.. whenever I think of testing it early in the morning, it's 10am Ohio time (I'm in Wisconsin), so it's always too late. I'm not a morning person. Haha! –  MacGyver Sep 13 '11 at 14:11

You can do this with variable substitutions, by changing...

SET THH=%time:~0,2%

...to...

SET THH=%time:~0,2%
SET THH=%THH: =0%

The second line replaces all spaces in %THH% with 0s.

See SET /? for more details.

share|improve this answer
    
Been meaning to test both of these answers for the past few weeks, but our server that I deploy to is 1 hour ahead.. whenever I think of testing it early in the morning, it's 10am Ohio time (I'm in Wisconsin), so it's always too late. I'm not a morning person. Haha! –  MacGyver Sep 13 '11 at 14:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.