hraja77
asked on
Need an ms dos script that will work out the date and ftp afile
Hi,
Please help;
I need an ms dos script that will work out todays date and grab the appropriate file and ftp this to another server.
Each night my sql database gets backed up in the format "abc_201109272000.bak".
So i need an ms dos script which finds todays date to match the date in the file name and then ftp this file toanother server;
thanks
H
Please help;
I need an ms dos script that will work out todays date and grab the appropriate file and ftp this to another server.
Each night my sql database gets backed up in the format "abc_201109272000.bak".
So i need an ms dos script which finds todays date to match the date in the file name and then ftp this file toanother server;
thanks
H
IF your systems date format is dd-mm-yyyy then this snipet will give you the file name....
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Date%") DO (
SET DayMonth=%%A
SET Month=%%B
SET Year=%%C
)
set FileName=abc_%Year%%Month% %DayMonth% .bak
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Date%") DO (
SET DayMonth=%%A
SET Month=%%B
SET Year=%%C
)
set FileName=abc_%Year%%Month%
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For getting dates fully internationalised I prefer to use....
This keeps it all inside a single cmd file and avoids calls to wscript etc.
REM Read the Date Seperator from the Registry
FOR /F "tokens=3" %%A IN ('REG QUERY "HKCU\Control Panel\International" /v sDate ') DO (
SET sDate=%%A
)
REM Now read the International date format used.
FOR /F "tokens=3" %%A IN ('REG QUERY "HKCU\Control Panel\International" /v iDate ') DO (
SET iDate=%%A
)
REM Now based on that info PARSE the date and create the file name
FOR /F "tokens=1-3 delims=%sDate%" %%A IN ("%Date%") DO (
IF "%iDate%"=="0" (
SET Day=%%B
SET Month=%%A
SET Year=%%C
)
IF "%iDate%"=="1" (
SET Day=%%A
SET Month=%%B
SET Year=%%C
)
IF "%iDate%"=="2" (
SET Day=%%C
SET Month=%%B
SET Year=%%A
)
)
set FileName=abc_%Year%%Month%%Day%.bak
This keeps it all inside a single cmd file and avoids calls to wscript etc.
ASKER
all sounds good - i also need the time to be in the filename also - how do i get this in ?
thanks
thanks
ASKER
ignore my last comment - thanks for all your helps
no problem, glad it helped.
Steve
Steve
yyyymmdd2000.bak ?
Would it be bst perhaps to get the latest file called abc_*.bak from that folder instead? We can get the date/time into the right format for you BUT does that time component change perhaps?