Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates In Batch File Question

Status
Not open for further replies.

dbrooks74

Programmer
Nov 13, 2001
105
US
I am hoping someone can help me to figure out what I am doing wrong. I have the following batch file

@Echo Off
Echo Copying All Files To Reports Folder
ECHO ------------------------- >> \\SERVER\FOLDER\ComUpload\%DATE%\ReportsFromCompany.txt
ECHO %username% - %DATE% %TIME% >> \\SERVER\FOLDER\ComUpload\%DATE%\ReportsFromCompany.txt
ECHO Moving The Following Files: >> \\SERVER\FOLDER\ComUpload\%DATE%\ReportsFromCompany.txt
MOVE /Y Z:\*.doc \\76718\Reports\ >> \\SERVER\FOLDER\ComUpload\%DATE%\ReportsFromCompany.txt
PAUSE


The place I am having a problem with is where it says %DATE%. I really need to have a new folder created every new date that this program is run so the document does not get huge and it is much more manageable.

I understand that %DATE% sends the date with the weekday in front of the date, and ideas on how I can strip that out, maybe that would work.

Thanks -dan
 
set NEWDATE=%DATE:~-10% gives me a value of DD/MM/YYYY in NEWDATE (Uk date format) - ie, last 10 characters of %DATE%.
 
That puts me on the right path. Thanks for your help. -db
 
unfortunately you cant use %DATE% directly as it contains forward slashes... try something like this.

******************************************************
@Echo Off

rem set up an env-var called output
FOR /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do SET output=\\SERVER\FOLDER\ComUpload\%%a-%%b-%%c-%%d

rem create the output directory
if not exist %output% mkdir %output%


Echo Copying All Files To Reports Folder
ECHO ------------------------- >> %output%\ReportsFromCompany.txt
ECHO %username% - %DATE% %TIME% >> %output%\ReportsFromCompany.txt
ECHO Moving The Following Files: >> %output%\ReportsFromCompany.txt
MOVE /Y Z:\*.doc \\76718\Reports\ >> %output%\ReportsFromCompany.txt
PAUSE
****************************************************

<< JOC >>

 
I combined your two responses and came up with the perfect solution. Thanks for all of your help. -db
 
Joc,

See you're still wielding a fair old command line!
 
Heh, it took me forever to try and work that stuff out years ago - nice to get some use out of it once in a while!!

:) JOC :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top