Computing.Net > Forums > Programming > Find oldest file in folder

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Find oldest file in folder

Reply to Message Icon

Name: JulianDavidson
Date: October 2, 2006 at 16:54:15 Pacific
OS: Win2k
CPU/Ram: 512
Comment:

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 off

set 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%



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: October 3, 2006 at 14:29:31 Pacific
Reply:

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%


0

Response Number 2
Name: JulianDavidson
Date: October 3, 2006 at 17:37:18 Pacific
Reply:

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.


0

Response Number 3
Name: dtech10
Date: October 4, 2006 at 18:59:48 Pacific
Reply:

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


0

Response Number 4
Name: JulianDavidson
Date: October 12, 2006 at 15:17:58 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Find oldest file in folder

.BAT To use FTP and find first file in folder www.computing.net/answers/programming/bat-to-use-ftp-and-find-first-file-in-folder/19566.html

batchRenaming files in Folder tree www.computing.net/answers/programming/batchrenaming-files-in-folder-tree-/18621.html

can we find a file in one folder? www.computing.net/answers/programming/can-we-find-a-file-in-one-folder/14587.html