I am new to windows batch scripting and struggling to achieve a task.
I have to create a script - to compress files particular files older than 90 days in its directory and corresponding sub directories
(Note: Compressed file should stay on the same directory or sub directory)
I have written a script with the help of google and this is not solving the purpose now.
It tries to delete all the files older than 90 days first and compresses the remaining later on.
** Now I should not delete them but just compress them . Is it possible to modify the below script
Code: Select all
@setlocal enabledelayedexpansion
@echo off
REM Setting root path and changing the directory to it
set ArPathname=D:\Data
pushd %ArPathname%
echo %ArPathname%
REM Deletes the files older than 90 days which matches the search criteria
forfiles -p %ArPathname% -s -m *2012*.txt -d -90 -c "cmd /c del @path"
forfiles -p %ArPathname% -s -m *201302*.csv -d -90 -c "cmd /c del @path"
echo after 90 days delete
REM Compresses the files using gzip which are less than 90 days old in the same folder
path=%path%;"D:\Data\Test"
for /f %%a in ('dir /s /b *2012*.txt *201302*.csv') do if not exist %%a.gz echo %%a | gzip %%a
echo after gzip
goto :eof
Can you please help me on this.
Many Thanks
Sheku