Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I need a batch file to list the directory
name satisfying the following condition:
-Display directory names which are greater
than or equal to 7days old from the last
modification date.
Example:
Test.cmd may be the batch file
C:\test-Dir may be the directory to be
verified.
The batch file must read all the root
directory names inside this C:\test-Dir and
should display the directory names which are
satisfying the condition
Note: The root directory names format may be
of any type like the following:
12.23.12
1234.3.2
2.2.1234
3.2.3.4.5
sample
sample dir
xxx yyy zzz
9.9_test
8_test
Im new to dos. I tried but cant find any
command for it.
Please help me on this issue.Thanks
Trusp

Why does this sound so eerily familiar?
These are NOT DOS directory names:
sample dir
xxx yyy zzzI've been using DOS for 22 years and have yet to make 'date math' work.
=====================================
If at first you don't succeed, you're about average.M2

These are sample names of the directories.
Actually i tried to say some sample directory
names inside the specified path.But to say as "xxx yyy" I specified wrongly.
i.e., What i mean is "program Files" there is
a directory inside the path.Similarly.,
Do we be able to access the directory last
modified date and check the date was >=7days
from accessing.Please help me on this.
thanks
Trusp

M2,
I appreciate your patience in trying to
educate people about difference between DOS
and the other stuff that looks like DOS,
which people use interchangingly.--
Holla.

try this...
coding is a bit messy though =P@echo off
SetLocal EnableDelayedExpansionset /a OLD=-7
set DIR=c:\set /a yyyy=%date:~-4%
set /a mm=%date:~3,2%
set /a dd=%date:~0,2%
echo TimeStamp=%yyyy%%mm%%dd% and OLD=%OLD%call :AdjustDate %OLD%
echo AdjustedTimeStamp=%yyyy%%mm%%dd%
set AdjustedTimeStamp=%yyyy%%mm%%dd%for /f "tokens=1* delims= " %%a in ('dir %DIR% /tw/ad/o-d/4^|findstr "\/"') do (
set filedate=%%a
set /a filedate=!filedate:~-4!!filedate:~3,2!!filedate:~0,2!
if !filedate! geq !AdjustedTimeStamp! (echo %%a %%b) else (goto :breakLoop)
)
:breakLoop
goto :eofREM **
REM FUNCTION AdjustDate(howmanydays as %1)
REM **
:AdjustDate
if %1==0 (goto :eof) else (if %1 GEQ 0 (set /a sign=1) else (set /a sign=-1))
set /a loopUntil=%1-!sign!for /L %%i in (0,%sign%,%loopUntil%) do (
set /a dd+=%sign%
::adjust dd & mm for + sign
for %%a in (29 30 31 32) do if !dd!==%%a (
call :GetNumOfDays !mm! !yy!
if !dd! gtr !numOfDays! (
set /a dd=1
set /a mm+=1
if !mm! gtr 12 (
set /a yyyy+=1
set /a mm=1
)
)
)
::adjust dd & mm for -sign
if !dd!==0 (
set /a mm-=1
if !mm!==0 (
set /a yyyy-=1
set /a mm=12
)
call :GetNumOfDays !mm! !yy!
set /a dd=!numOfDays!
)
:: echo i=%%i !yyyy!-!mm!-!dd! numDays=!numOfDays!
echo >nul
)
goto :eofREM **
REM FUNCTION GetNumOfDays month as %1, year as %2
REM **
:GetNumOfDays
for %%i in (1 3 5 7 8 10 12) do if %1==%%i set /a numOfDays=31
for %%i in (4 6 9 11) do if %1==%%i set /a numOfDays=30
if %mm%==2 (
set /a remainder=%2-%2/4*4
if !remainder!==0 (set /a numOfDays=29) else (set /a numOfDays=28)
)
goto :eof

sorry, there is a bug in the code above, when day or month is the 8th or 9th. it gives octal error.
i'll post a fix solution maybe tomorrow.
basically i know 2 ways to do it:
1. parse the "/" in date format
2. set /a dd=1%dd%-100

i just learn new trick from "razor" in the other thread using vbs. it makes the code neater and simple.
i also have the code without vbs if needed.
@echo off
SetLocal EnableDelayedExpansionset /a DAYS=-7
set DIR=c:\call :DateAdd(!DAYS!)
echo DateAdd=!DateAdd!for /f "tokens=1* delims= " %%a in ('dir %DIR% /tw/ad/o-d/4^|findstr "\/"') do (
set filedate=%%a
set /a filedate=!filedate:~-4!!filedate:~3,2!!filedate:~0,2!
if !filedate! geq !DateAdd! (echo %%a %%b) else (echo NOT %%a)
)
:breakLoop
goto :eof
REM Function DateAdd(day as %1) Return Int yyyymmdd
:DateAdd
set /a day=%1
echo d=DateAdd("d",WScript.Arguments(0), date) > #.vbs
echo WScript.Quit DatePart("yyyy", d) * 10000 + DatePart("m", d) * 100 + DatePart("d", d) >> #.vbs
cscript //NOLOGO #.vbs !day!
Set /a DateAdd=%ErrorLevel%
del #.vbs
goto :eof

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |