Batchscrip to zip files by date and del files

December 13, 2010 at 04:51:27
Specs: Windows Server 2k3 sp2
Hi,
I'm trying to figure out how I can make a script that does 3 things ( or 4 depends on how it's done ).
I have a folder with a lot of log files that takes up space. So I have made a script to remove all files older than 21 days:

Forfiles -s -m *.* -d -21 -c "cmd /c del /q @path"

But we also need a way to script that it always makes a .zip file with each days logs. Aka. take it's 2010/12/13 today and I want to .zip all files for each day before that. So each day gets their own .zip file. Also at the same time we need the files that has been zipped to be deleted so they don't take up space.

Can all this be done in a .bat script or do I need more cooks in this soup?


See More: Batchscrip to zip files by date and del files

Report •

#1
December 13, 2010 at 05:59:50
Hopefully not so many cooks that the soup is spoiled. Please run this and post output.

=============================================
@echo off > %TEMP%\# & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/s %TEMP%\#') do (
echo.%%a
echo.%%~Ta
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
December 13, 2010 at 06:05:13
C:\Documents and Settings\Administrator>@echo off > %TEMP%\# & setLocal EnableDE
LAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/s %TEMP%\#') do (
%%a was unexpected at this time.
echo.%%a
%%a
echo.%%~Ta
%%~Ta


Report •

#3
December 13, 2010 at 06:19:09
I unburied the default %TEMP% a long time ago..

=============================================
@echo off > # & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b #') do (
echo.%%a
echo.%%~Ta
)


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
December 13, 2010 at 06:47:30
C:\Documents and Settings\Administrator>@echo off > # & setLocal EnableDELAYedeX
pansion

for /f "tokens=* delims= " %%a in ('dir/b #') do (
%%a was unexpected at this time.
echo.%%a
%%a
echo.%%~Ta
%%~Ta


Report •

#5
December 13, 2010 at 06:49:55
Past it into a text file. Notepad will do. And name it MY.BAT and run it.


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
December 13, 2010 at 06:55:37
I get a file with # as a name, that's empty.

Report •

#7
March 1, 2011 at 03:52:01
Hey Nemie,

Was there a solution for this? I am searching for one now..

Manoj


Report •

#8
March 1, 2011 at 23:59:09
No, there wasn't I'm afraid.

Report •

#9
March 8, 2011 at 23:45:16
THe solution woulda been [ but woulda don't help] to run the code I posted 3 months ago and post the output.

I don't need to be told that it creates a zero length file named #.


=====================================
Life is too important to be taken seriously.

M2


Report •

#10
March 8, 2011 at 23:51:18
I did post the output twice, and it just posted back the same thing that I wrote in... So... I felt it didn't really do anything -.-

Report •

Ask Question