Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have learned lots through reading this site (usually find it via google). It's encouraged me to set up and account and pose some more questions, and hopefully answer some as time goes by...
Below is a script I use to create a simple report. You can run it in any folder that has a few subfolders with files in them to see what it does. (though as it is it will only find/count tif files).
I want to complicate it a bit and have the output not only list how many files there are in each folder/tree, but also show the filename and date of the file with the oldest Last Modified Date.
I would also like the columns to line up nicely, if possible.
Any takers?
Thanks in advance.
Julian.
@echo offset pathname=G:\
set fileName=report.txt::Message at top of report.
echo Current counts of jobcards awaiting action in the G drive folders: > %filename%
echo. >> %filename%::Report creation
for /f "delims=" %%a in ('dir /b /ad 2^>NUL') do call :PROCESSDIR "%%a"::Message on screen and email
:: echo This report was generated on %date% at %time%. (this line now goes on email)::Message at bottom of report (file).
echo. >> %filename%
echo This report was generated on %date% at %time%. >> %filename%goto :EOF
:PROCESSDIR
pushd.
cd %1
set /a cnt=0
set oldest=for /f "delims=" %%a in ('dir "*.tif" /s /b /a-d /on 2^>NUL') do (
set /a cnt+=1
)popd
echo %~1 = %cnt%
echo %~1 = %cnt% >>%fileName%

Hi
This find the oldest, and will echo "TAB" help to space data out.
@echo off
for /f "tokens=1-4 delims= " %%a in ('dir /a-d ^| find ":"') do set Oldest=%%a %%d
echo Oldest=%Oldest%

Hi
Thanks for your reply...I put that into a new batch file, but I get "the syntax of the command is incorrect." before it runs the first line... am i missing something?
Thanks
Julian.

Hi Julian
The first two lines are all on one line and the third echo Oldest=%Oldest%
Is this your problem.
or maybe it's the quotes
(' dir /a-d ^| find ":" ')
or maybe the wrong pipe symbol | looks like
two upright dashs on the keyboard not the single dash.
Hope this helps

Hi
Thanks for your reply..I run the following script, but the result is definitley not the oldest file in the folder:
@echo off
for /f "tokens=1-4 delims= " %%a in ('dir /a-d /od /tw ^| find ":"') do set Oldest=%%a %%d
echo Oldest=%Oldest%Any thoughts?
Cheers
Julian.

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

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