Help me !! do condicion in batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jota
Posts: 2
Joined: 14 Dec 2012 04:55

Help me !! do condicion in batch

#1 Post by Jota » 14 Dec 2012 05:05

I everybody im starting now with batch scripting and i nedd to implement a script that :

find for all files "*.log* in folder
after
rename this files with de current date , zip this files and move all files ziper for other folder..

i have these code..

onde batch file with

@echo off
for /f "tokens=*" %%a in ('dir /b *.log') do C:\directory\archive.bat %%a
exit 0

and other

ren %1 %1_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2% %%a
zip -m %1_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%.zip %1_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%
move /Y *.zip* "C:directory\log\BCK_ZIP"
pause


but i want put all in only in file..

Can you help me..

when i put

@echo off
for /f "tokens=*" %%a in ('dir /b *.log') do (
ren %1 %1_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2% %%a
zip -m %1_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%.zip %1_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%
move /Y *.zip* "C:directory\log\BCK_ZIP")

pause

ERROR SYNTAX

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Help me !! do condicion in batch

#2 Post by abc0502 » 14 Dec 2012 08:16

The %%a is represented in the other batch as %1, just replace %1 with %%a

@echo off
for /f "tokens=*" %%a in ('dir /b *.log') do (
ren %%a %%a_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2% %%a
zip -m %%a_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%.zip %%a_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%
move /Y *.zip* "C:directory\log\BCK_ZIP")

pause


try it now but this blue %%a i don't know what it should be, may be you wrote it by mistake :?:

Jota
Posts: 2
Joined: 14 Dec 2012 04:55

Re: Help me !! do condicion in batch

#3 Post by Jota » 14 Dec 2012 08:39

Hi!!

TY , but after change what you say when i run this script i recived one message "syntax is not correct" in a lopp that not end..

Can you help me ..i think that is a small problem..

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help me !! do condicion in batch

#4 Post by foxidrive » 14 Dec 2012 09:00

Try this: but all date/time inside the loop will be the same, it is only evaluated once - so the first log file will have the same date and time in the name as the last log file.

Code: Select all

@echo off
for /f "tokens=*" %%a in ('dir /b *.log') do (
ren "%%a" "%%~na_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%%~xa"
zip -m "%%~na_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%.zip" "%%~na_%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%%~xa"
move /Y "*.zip" "C:directory\log\BCK_ZIP"
)
pause

Post Reply