1

Have a need to find files in a folder that are older than X hours. Have to do this in batch because this is an older server that we don't want to load anything else on. This is based on Find out if file is older than 4 hours in Batch file, but that solution was written for only for one static filename. I have adjusted it for multiple files, and US date format, but the problem I am having in the file minutes it is picking up the 'a' or 'p' for am or pm. I have posted my partial solution below (does not perform date math and echos to screen filename and date/time values). Any ideas on how to get rid of a or p?

rem extract current date
for /f "tokens=1-5 delims=.,/ " %%a in ("%date%") do (
  set day=%%c&set mon=%%b&set yr=%%d
)
REM Extract Current Time
for /f "tokens=1-5 delims=.:, " %%a in ("%time%") do (
set hr=%%a&set min=%%b
)
REM BUILD LIST OF FILES IN DIRECTORY
dir /B /O:N c:\mydir\*myfilestub*.* >list.txt
Rem LOOP THROUGH LIST OF FILES and CALL SUBROUTINE TO CHECK FILE DATE 
For /F %%A in (list.txt) DO (CALL :CHECKFILE %%A)
GOTO :EOF

:CHECKFILE
REM  CHECKING FILE %* 
set filename=%*
rem extract file date and time
for /f "tokens=1-5 delims=.:,/ " %%a in ('"dir c:\mydir\%filename%|find "%filename%""') do (
  set fday=%%a&set fmon=%%b&set fyr=%%c&set fhr=%%d&set fmin=%%e
)        
ECHO   %FILENAME% %fday% %fmon% %fyr% %fhr% %fmin%
GOTO :EOF
Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
KMC
  • 31
  • 1
  • 4
  • First of all, AM/PM? Why not 24-hour dates? Afaik its there by default. Also, if you are on Windows there are other native batch script languages you can use to better write a more reliable script that doesn't depend on your current system settings, such as VBScript, CScript and it can even run JavaScript as batch script. – Havenard Mar 11 '13 at 15:40
  • @Havenard, we could probably use a vbscript, but this is an old Windows 2000 (insert shudder here) server running legacy software and trying to avoid any programming in maintaining it. Barely getting past "freeze" on server to get a batch script running to solve this particular problem. – KMC Mar 11 '13 at 15:46

1 Answers1

0

Thanks to http://www.dostips.com/DtTipsStringManipulation.php, I got the answer I was needing, just added a line below the for loop that was getting the file date

SET fmin=%fmin:~0,2%

It is nothing short of amazing what you can still accomplish with just DOS on a windows server. I know this script could be cleaned up and shortened I am sure, but it suits my purposes.

KMC
  • 31
  • 1
  • 4