Hi All,
I have a simple batch file which uses CURL to FTP a file. The file name has a dynamic date like:
LGWcapture-"yyyymmdd"-"hhnnss".txt
The "yyyymmdd"-"hhnnss" changes each time the file is updated.
My batch file is:
curl -T c:\ComCapV4\logs\LGWcapture-"yyyymmdd"-"hhnnss".txt ftp://mydomain.com/httpdocs/xml/ --user name:password
How would I include the date part of the file in my script.
Many thanks in advance.
Dereck
Using a variable in file name when copying
Moderator: DosItHelp
Re: Using a variable in file name when copying
You can use this code to get date time (your computer time)
Code: Select all
set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set day=%Date:~-10,2%
if "%Date:~-10,2%"=="%Date:~-10,2%" set day=-%Date:~-10,2%
set month=%Date:~-7,2%
if "%Date:~-7,2%"=="%Date:~-7,2%" set month=-%Date:~-7,1%
set year=%Date:~-4,4%
if "%Date:~-4,4%"=="%Date:~-4,4%" set year=-%Date:~-2,4%
ipconfig>"%CD%\log\%COMPUTERNAME%__[%day%_%month%_%year%_%hh%_%time:~3,2%_%time:~6,2%].txt"
Re: Using a variable in file name when copying
This is not a good approach. In theory time/date can change between two SET commands so you could get:
Example: currently the date is 31-dec-2009, time: 23:59:59.99 (or very close)
day=31
here date changes from 31-dec-2009 to 1-jan-2010
month=1 (instead of 12)
year=2010 (instead of 2009)
You have to use something like this:
currdatetime=%time% %date%
and then you have to manipulate with a currdatetime variable.
(better solution is to use FOR command)
Saso
Example: currently the date is 31-dec-2009, time: 23:59:59.99 (or very close)
day=31
here date changes from 31-dec-2009 to 1-jan-2010
month=1 (instead of 12)
year=2010 (instead of 2009)
You have to use something like this:
currdatetime=%time% %date%
and then you have to manipulate with a currdatetime variable.
(better solution is to use FOR command)
Saso