سؤال

I am a total newbie at windows scripting having spent over 13 yrs scripting in Unix shell. I need help in finding a way to find a folder last modified about 30 days back and then zip the folder and move it to another "Archive" folder. Folder structure is like the following :

D:\AuditFiles\2013.05
D:\AuditFiles\2013.06
D:\AuditFiles\Archive

So aim is to move 2013.05 into Archive directory after zipping it up.

I've tried forfiles.exe which doesnt allow me to skip the folder Archive and I've tried dir /ad but that doesnt allow me to specific last modified days been +30.

هل كانت مفيدة؟

المحلول 2

This is one method to get the oldest folder, excluding Archive, which seems to be what you need.

@echo off
pushd "D:\AuditFiles\"
for /f "delims=" %%a in ('dir /b /ad /o-d') do (
if /i not "%%a"=="Archive" set "folder=%%a"
)
echo oldest folder is "%folder%"
popd

نصائح أخرى

The easy way, assuming your date format is Mo 07/01/2013, check this with the command echo %date%:

@echo OFF &setlocal
REM %date% format is "Mo 07/01/2013"
FOR /f "tokens=2,4delims=/ "  %%a IN ("%date%") DO SET /a month=%%a, year=%%b
IF %month% equ 1 (
    SET /a month=12
    SET /a year-=1
) ELSE SET /a month-=1
if %month% lss 10 SET "month=0%month%"
SET "folderToSearch=%year%.%month%"
IF NOT EXIST "D:\AuditFiles\%folderToSearch%\" ECHO Folder NOT found: %folderToSearch%&goto:eof
ZIP [put options for your ZIP app here] "D:\AuditFiles\Archive\%folderToSearch%.zip" "D:\AuditFiles\%folderToSearch%"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top