newest files in a tree

#1
Has anyone already written a script for finding the n more recently modified files in a directory tree, ideally limited by a wildcard?

Also, how about something like dir /bs that includes just the file name and date
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#2
The first should be doable using date ranges.
The switch /[d0] will only select files matching today's date for example.

The second is doable using PDIR.

pdir /s /(dm/d/y fpn)

-Scott




Has anyone already written a script for
finding the n more recently modified files in a directory tree, ideally
limited by a wildcard?

Also, how about something like dir /bs that includes just the file name
and date
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,599
46
Albuquerque, NM
prospero.unm.edu
#3
Has anyone already written a script for finding the n more recently modified files in a directory tree, ideally limited by a wildcard?
Sounds like a good candidate for plugin commands or functions, perhaps returning results in an array variable. Vincent's 4UTILS has @OLDEST and @NEWEST; I don't know whether they can recurse into subdirectories (the docs are a bit laconic.)
 
May 31, 2008
382
2
#4
You could also use Jim Cook's timedir.exe. To find the 3 most recent .txt files in a tree starting at c:\folder:
Code:
TIMEDIR /A-d /S /F /O:-d /^>3 c:\folder\*.txt
Note that the seemingly equivalent TCMD version:
Code:
DIR /A-d /S /F /O:-d c:\folder\*.txt | HEAD /N3
does not yield the three most recent files in the tree, but the three most recent files in the first listed folder.
TIMEDIR first creates the whole output list, then it sorts it.

To include just the file name and modification date/time:
Code:
TIMEDIR /S /F /(F TMW/TDW/TYW TTW)
 
#5
The following BTM can be modified to return more than the most recent one

:: Determine latest file is folder tree and display
::
:: =======================================================================================================================*setlocal
*unalias *
unset /q f t
set d=%@if[%# eq 0,%_cwd,%1]
pushd %@full[%d]
pushd %d
set t=0
global /i /q (
set i="%@execstr[dir /a: /b /f /k /m /o:-d]"
echo %@if[isdir[%i],D,F] %i
set x=%@fileage[%i]
if %x gt %t (
set t=%x
set f=%i
)
)
pause
cls
echo %=nTree scanned: %@full[%d]
echo %=n Latest File:
echo File Path: %@path[%f]
echo File Name: %@filename[%f]
echo File Size: %@comma[%@filesize[%f]]
echo Date / Time: %@filedate[%f] %@filetime[%f]
popd
popd

----- Original Message -----
From: Roedy
To: [email protected]
Sent: Thursday, October 13, 2011 01:05 PM
Subject: [T&T - Scripting-t-3290] newest files in a tree


Has anyone already written a script for finding the n more recently modified files in a directory tree, ideally limited by a wildcard?

Also, how about something like dir /bs that includes just the file name and date
 
Aug 9, 2009
133
0
#6
: Has anyone already written a script for finding the n more recently modified files in a
directory tree,
: ideally limited by a wildcard?
:
: Also, how about something like dir /bs that includes just the file name and date

This example exists in V8 help file .. %@execstr[*dir /a:-d /h /o:-t /f ] alias it LF
bingo
 
#7
Kachupp wrote:
|| Has anyone already written a script for finding the n more recently
|| modified files in a directory tree, ideally limited by a wildcard?
|
| This example exists in V8 help file .. %@execstr[*dir /a:-d /h /o:-t
| /f ] alias it LF bingo

That gives only ONE file, the OP requested a variable number "n". I'd
recommend TIMEDIR instead of a batch file.
--
Steve
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#9
If I want to find the 10 newest files in
a directory I would use DIR piped into HEAD or TAIL.

dir /a:-d /od /km |! tail /N10

or

dir /a:-d /o-d /km |! head /N10

alias newest=`dir /a:-d /od /km %2$
|! tail /N%@if[%1.==.,10,%1]`

newest
newest 10 *.bat
newest 5 *.bat;*.btm

-Scott




Quote:


Originally Posted by Steve
Fabian
That gives only ONE file, the OP requested
a variable number "n". I'd recommend TIMEDIR instead of a batch
file.
TIMEDIR does look like the most elegant
approach proposed thus far.
 
#11
This is one of the things I was hoping to solve with the "DIR /S sorted
together" request.

If I had been more clear that I wanted the full DIR output with whatever
switches applied, this would have been solved by DIR in the latest TCC.

I (obviously) use TIMEDIR to solve this issue as well.

On Thu, Oct 13, 2011 at 15:45, Charles Dye <>wrote:


> ---Quote (Originally by samintz)---
> If I want to find the 10 newest files in
> a directory I would use DIR piped into HEAD or TAIL.
> ---End Quote---
> That'll give the n most recent in a single directory....
>
>
>
>
>


--
Jim Cook
2011 Monday: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Tuesday.
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#12
This is a TCC solution that doesn't rely
on an external plugin or app.

pdir /a:-d /s /(dy/m/d th:m z
fpn) |! sort |! tail /N10

or

pdir /a:-d /s /(dy/m/d th:m z
fpn) |! sort /r |! head /N10

alias newest=`pdir /a:-d /(dy/m/d th:m
z fpn) %2$ |! sort |! tail /N%@if[%1.==.,10,%1]`

newest
newest 5
newest 10 /s
newest 10 *.cpp /s

-Scott





This is one of the things I was hoping
to solve with the "DIR /S sorted
together" request.

If I had been more clear that I wanted the full DIR output with whatever
switches applied, this would have been solved by DIR in the latest TCC.

I (obviously) use TIMEDIR to solve this issue as well.

On Thu, Oct 13, 2011 at 15:45, Charles Dye <>wrote:


Quote:



> ---Quote (Originally by
samintz)---

> If I want to find the 10 newest files in
> a directory I would use DIR piped into HEAD or TAIL.
> ---End Quote---
> That'll give the n most recent in a single directory....
>
>
>
>
>

--
Jim Cook
2011 Monday: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Tuesday.
 
#13
Scott,

Why does your lines wrap so early? Are you posting thru the website or what email client?
----- Original Message -----
From: samintz
To: [email protected]
Sent: Thursday, October 13, 2011 09:06 PM
Subject: RE: [T&T - Scripting-t-3290] Re: newest files in a tree


This is a TCC solution that doesn't rely
on an external plugin or app.

pdir /a:-d /s /(dy/m/d th:m z
fpn) |! sort |! tail /N10

or

pdir /a:-d /s /(dy/m/d th:m z
fpn) |! sort /r |! head /N10

alias newest=`pdir /a:-d /(dy/m/d th:m
z fpn) %2$ |! sort |! tail /N%@if[%1.==.,10,%1]`

newest
newest 5
newest 10 /s
newest 10 *.cpp /s

-Scott





This is one of the things I was hoping
to solve with the "DIR /S sorted
together" request.

If I had been more clear that I wanted the full DIR output with whatever
switches applied, this would have been solved by DIR in the latest TCC.

I (obviously) use TIMEDIR to solve this issue as well.

On Thu, Oct 13, 2011 at 15:45, Charles Dye <>wrote:


Quote:




Quote:
> ---Quote (Originally by

samintz)---


Quote:
> If I want to find the 10 newest files in
> a directory I would use DIR piped into HEAD or TAIL.
> ---End Quote---
> That'll give the n most recent in a single directory....
>
>
>
>
>


--
Jim Cook
2011 Monday: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Tuesday.
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#14
Lotus frickin' Notes.

-Scott



Scott,

Why does your lines wrap so early? Are you posting thru the website or
what email client?
----- Original Message -----
From: samintz
To: [email protected]
Sent: Thursday, October 13, 2011 09:06 PM
Subject: RE: [T&T - Scripting-t-3290] Re: newest files in a tree


This is a TCC solution that doesn't rely
on an external plugin or app.

pdir /a:-d /s /(dy/m/d th:m z
fpn) |! sort |! tail /N10

or

pdir /a:-d /s /(dy/m/d th:m z
fpn) |! sort /r |! head /N10

alias newest=`pdir /a:-d /(dy/m/d th:m
z fpn) %2$ |! sort |! tail /N%@if[%1.==.,10,%1]`

newest
newest 5
newest 10 /s
newest 10 *.cpp /s

-Scott





This is one of the things I was hoping
to solve with the "DIR /S sorted
together" request.

If I had been more clear that I wanted the full DIR output with whatever
switches applied, this would have been solved by DIR in the latest TCC.

I (obviously) use TIMEDIR to solve this issue as well.

On Thu, Oct 13, 2011 at 15:45, Charles Dye <>wrote:


Quote:




Quote:

> ---Quote (Originally by
samintz)---


Quote:

> If I want to find the 10 newest files in
> a directory I would use DIR piped into HEAD or TAIL.
> ---End Quote---
> That'll give the n most recent in a single directory....
>
>
>
>
>

--
Jim Cook
2011 Monday: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Tuesday.
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#16
It appears to wrap after I hit send. It
certainly isn't wrapped as I write it. And it's odd because some
things wrap and some things don't. I haven't quite figured that out
yet.

-Scott




Quote:


Originally Posted by samintz

Lotus frickin' Notes.
You can't use WordStar as your editor?
Or SpeedScript, or whatever?
 
#17
It appears to wrap after I hit send
What is your outgoing mail format set to?? I suspect that MIME would work better than Rich Text (this can be set on the location document's Mail tab). There is also a user preference setting that allows you to control whether Internet messages are sent as plain text, HTML or both although exactly where that is depends on which version of Notes you are using.
 
#18
Hi,

we surely all know, that 4dos/4nt/tcc is the real, one and only religion ;-)
But beside of that I often use "logparser" from M$.
It can parse a lot of file types, even the windows registry or the filesystem by using a sql-like syntax.
e.g.
Code:
logparser -i:fs -rtp:-1 -q:on -recurse:-1 "
select top 10 to_string( LastWriteTime, 'yyyy-MM-dd hh:mm:ss') as lwt,
path, name, attributes from 'd:\temp\*.*'
where substr(attributes,0,1) <> 'D' order by lwt  desc "

2106-01-01 06:14:18 D:\temp\alter_pc\dosbox\games\prehistorik2\MYSTERY.TRK  MYSTERY.TRK                 -A-------
2023-09-13 01:44:46 D:\temp\alter_pc\dosbox\games\prehistorik2\PRESENTA.TRK PRESENTA.TRK                -A-------
2023-09-13 00:27:14 D:\temp\alter_pc\dosbox\games\prehistorik2\GLACE.TRK    GLACE.TRK                   -A-------
2023-09-13 00:20:30 D:\temp\alter_pc\dosbox\games\prehistorik2\MINES.TRK    MINES.TRK                   -A-------
2011-10-24 22:18:30 D:\temp\etilqs_u7QuCRx80iuEtBJlbSiC                     etilqs_u7QuCRx80iuEtBJlbSiC -A-H-----
2011-10-24 22:18:03 D:\temp\~DF2B334647DD15BC79.TMP                         ~DF2B334647DD15BC79.TMP     -A-------
2011-10-24 22:18:03 D:\temp\~DF1ACDBCF7BC07A04D.TMP                         ~DF1ACDBCF7BC07A04D.TMP     -A-------
2011-10-24 22:09:11 D:\temp\etilqs_c4qTaCzJYCb4YIeS7L7v                     etilqs_c4qTaCzJYCb4YIeS7L7v -A-H-----
2011-10-24 22:04:39 D:\temp\etilqs_iAtNyyYvTRbxJosTI2he                     etilqs_iAtNyyYvTRbxJosTI2he -A-H-----
2011-10-24 20:19:05 D:\temp\etilqs_cmyqv3flU1hgsynka8P6                     etilqs_cmyqv3flU1hgsynka8P6 -A-H-----
 
#20
From: Charles Dye
| And here 'tis: Sift Plugin

It is highly usable as is, thanks, but for just finding the timestamp of the latest file in a directory tree it requires a very complex command line, and the result needs lot of work to be usable. Here are my

SUGGESTIONS:

- should post in TC_PLUGINS!

- should use /S for including subdirectories; possibly incorporating the /S+ etc. syntax (lots of work... unless you can get Rex to provide access to his code)

- should use /T: for type of timestamp, to match TCC

- should be able to combine multiple options with a single /, e.g., /ins instead of /i /n /a

- should make file specification last element on command line, so multiple specifications could be accommodated (see also suggestion about keyword vs. positional parameters)

- should make a single file the default

- with file specification last, absent specification should default to ALL as in DIR

- sometimes (esp. when copying files newer than the last download, e.g., from an ftp site) I want only the timestamp of the latest file in a (local) directory[tree], in a format suitable for a file selection (or exclusion) range, e.g.:
/![d%_sift_timestamp]

- along with that, maybe a whole set of internal variables, e.g., _sift_dirs, _sift_files, _sift_errors; also the information on the extreme entry found: _sift_file, _sift_size, _sift_time - these would be the same values returned in the array when just one result is asked for.

- if the found entry's information is made available through variables, the array itself should be optional

- any non-mandatory parameters should not be "positional" ones, they should be "keyword" parameters, i.e, specified using an option flag, with optional space between the flag and the parameter value
--
HTH, Steve
It
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,599
46
Albuquerque, NM
prospero.unm.edu
#21
- should use /S for including subdirectories; possibly incorporating the /S+ etc. syntax (lots of work... unless you can get Rex to provide access to his code)
/R for recursion was a deliberate choice, since I'm using /S for Smallest. (Think of it is FOR compatibility....) As for the /S+ syntax, it's all very cool but I don't think I've ever had a need for it.

- should be able to combine multiple options with a single /, e.g., /ins instead of /i /n /a
Never liked such syntax; it causes problems if you have multiletter options (and there's already one in there.) I could easily allow you to mash options together without spaces, but you'd have to provide the slash before each one.

- should make file specification last element on command line, so multiple specifications could be accommodated (see also suggestion about keyword vs. positional parameters)
Or perhaps allow args in any order, but require a double percent sign before the array name?
 
#22
From: Charles Dye
| Originally Posted by Steve Fabian
| - should use /S for including subdirectories; possibly incorporating
| the /S+ etc. syntax (lots of work... unless you can get Rex to
| provide access to his code)
|
| /R for recursion was a deliberate choice, since I'm using /S for
| Smallest. (Think of it is FOR compatibility....) As for the /S+
| syntax, it's all very cool but I don't think I've ever had a need for
| it.

We can learn to like it...

| Quote:
| - should be able to combine multiple options with a single /, e.g.,
| /ins instead of /i /n /a
|
| Never liked such syntax; it causes problems if you have multiletter
| options (and there's already one in there.) I could easily allow you
| to mash options together without spaces, but you'd have to provide
| the slash before each one.

Actually it already works without space before /!

| Quote:
| - should make file specification last element on command line, so
| multiple specifications could be accommodated (see also suggestion
| about keyword vs. positional parameters)
|
| Or perhaps allow args in any order, but require a double percent sign
| before the array name?

Or make SIFT the default array name. No "%%" - it gets mangled too often! I prefer the keyword-parameter approach...
--
Steve
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,599
46
Albuquerque, NM
prospero.unm.edu
#23
- should make file specification last element on command line, so multiple specifications could be accommodated (see also suggestion about keyword vs. positional parameters)
On second thought, rather than multiple arguments, wouldn't it make more sense just to (correctly) support include lists?
 
#24
From: Charles Dye
| On second thought, rather than multiple arguments, wouldn't it make
| more sense just to (correctly) support include lists?

Only if you support multiple include lists! A very likely scenario for using SIFT has two or more base directories. Only the first element of an include list may contain a path.
--
Steve
 
#28
Charles,

Is that the browser cache or the DNS cache? I have no problems with geting the current broswer pages but just asking for possible futire reference.
----- Original Message -----
From: Charles Dye
To: [email protected]
Sent: Thursday, November 03, 2011 12:36 PM
Subject: RE: [T&T - Scripting-t-3290] Re: newest files in a tree


Quote:
Originally Posted by JohnQSmith
Currently the download v0.30.0 is still posted, not the documented v0.50.0. Or do I need to purge my browser cache?

It's definitely 0.50. A forced refresh ought to do it; or purge the cache if that doesn't work.
 
Jan 19, 2011
581
10
Norman, OK
#30
I reset/deleted the browser cache and still got the old file. Apparently it was the cache on our proxy server. I was able to download it using my iPhone and then email to myself.