I would like to add the date in yyyy-mm-dd format, if possible. I am using this command:
"C:\Program Files\7-zip\7z" a -r TNG-%date%.7z * , but all it does is put the day of the week in the archive name such as TNG-Wed.
Is there a way to get an archive name such as TNG-2004-11-17 ?
%date% is an windows variable, it has a space in it.
If you put quotes around is you'll get the whole date.
"c:\Program Files\7-zip\7z" a TNG-"%date%".7z *
Creating archive TNG-wo 17-11-2004.7z
suggestion: make sure in your windows > control panel > regional setttings you have the 'date' in '-' format rather than '/' format
I guess I should have explained better what it is I'm trying to do. I would like to have a batch file to backup some files. The relevant part looks like this:
echo * Back up TNG Table Files? *
echo * Press Enter to continue... *
cd \Program Files\TNG\
"C:\Program Files\7-zip\7z" a -r TNG-"%date%".7z *
echo * Please insert Zip Disk into your F: Drive *
echo * Press enter when ready *
if exist f:\Tng\*.7z Del f:\Tng\*.7z
move *.7z f:\Tng\
When using the command as suggested, it actually makes subdirectories in the TNG dir using the date as the names of the subdir's, like so:
C:\Program Files\TNG\TNG-Wed 11\17\2004.7z\ and will not move the file to the F: drive. If I put a space between the file name and the date like this:
"C:\Program Files\7-zip\7z" a -r TNG- "%date%".7z * it will compress all the files but will not add the date, but it will move the file to the F: drive.
This works for me:
"c:\Program Files\7-zip\7z" a -r "TNG-%date%.7z" *
Creating archive TNG-wo 17-11-2004.7z
Is this with version 4 or 3?
You can use absolute pathnames again with 4
maybe something like:
"c:\Program Files\7-Zip\7z.exe" a -r "f:\TNG-%date%.7z" "c:\Program Files\TNG\*"
I tried it as suggested:
"c:\Program Files\7-zip\7z" a -r "TNG-%date%.7z" * and still get the file as subdir's, ie \TNG-Wed 11\17\2004.7z\
I'm using ver. 4.11b and WinXp. I tried the absolute pathname:
"c:\Program Files\7-Zip\7z.exe" a -r "f:\TNG-%date%.7z" "c:\Program Files\TNG\*" and still get the same result. Is there any other "date" format that might work? Obviously, %date% doesn't like me :)
I'm using this, but you must download Datetime.com from http://plop.at
under WinXP you may parse DATE /t (or /d i don't know now) but this work fine from W95 to WXP
It compress drectories to the archives with time in the name, connect to the FTP, create directory (wtih time) on the FTP and upload files
:: smaze stare archivy
echo A|del archivy\*.*
:: A as Ano - for czech version
:: echo Y|del archivy\*.*
:: fo english
:: nastavi do promenne CAS aktualni datum a cas
datetime set CAS=!y_!m_!d__!H_!M> cas.bat
:: SPAKUJE SLOZKY PRO ZALOHOVANI
7-Zip\7z.exe a -r -mx=1 archivy\Dokumenty__%CAS%.7z "..\Dokumenty"
7-Zip\7z.exe a -r -mx=1 archivy\J__%CAS%.7z "..\J"
7-Zip\7z.exe a -r -mx=1 archivy\Posta__%CAS%.7z "..\WINDOWS\Application Data\Identities"
7-Zip\7z.exe a -r -mx=1 archivy\Posta_adresy__%CAS%.7z "..\WINDOWS\Application Data\Microsoft\Address Book"
7-Zip\7z.exe a -r -mx=1 archivy\CS_OL30__%CAS%.7z "..\CS_OL30"
:: VYTVORENI SOUBORU S PRIKAZY PRO FTP
> script.ftp ECHO open 192.168.15.139
>>script.ftp ECHO user_uloziste
>>script.ftp ECHO nopassword
>>script.ftp ECHO lcd c:\zaloha\archivy
>>script.ftp ECHO cd %STANICE%
>>script.ftp ECHO mkdir %CAS%
>>script.ftp ECHO cd %CAS%
>>script.ftp ECHO binary
>>script.ftp ECHO prompt n
>>script.ftp ECHO mput *
>>script.ftp ECHO by
:: SPUSTI UKECANE FTP S SOUBOREM, CO OBSAHUJE PRIKAZY
FTP -v -s:script.ftp
I use Win NT 4.0, and the righe way to obtain the values for day, month and year is:
if exist MyPath\MyBackup.zip for /f "tokens=1-4 delims=/ " %%a in ('date/t') do ren MyPath\MyBackup.zip "%%d-%%c-%%b% MyBackup.zip"
it let me to obtain a file named like "2004-11-22 name.zip"
In WinXP 'date' is in a different order, in fact I had some problem when I was trying the batch on my pc (XP) and then in the final pc (NT)
for XP you have to use the following code:
for /f "tokens=1-4 delims=/ " %%a in ("%date%") do ren MyPath\MyBackup.zip "%%c-%%a-%%b%~MyBackup.zip"
use %DATE:~4,2%_%DATE:~7,2% to get it formatted nicer. (for non-english codepages, this needs to be modified a bit)
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.