1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

newest files in a tree

Discussion in 'T&T - Scripting' started by Roedy, Oct 13, 2011.

  1. Roedy

    Joined:
    Jun 8, 2008
    Messages:
    120
    Likes Received:
    2
    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
     
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,191
    Likes Received:
    11
    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
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    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.)
     
  4. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    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. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,028
    Likes Received:
    0
    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: CSGalloway@nc.rr.com
    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
     
  6. Kachupp

    Joined:
    Aug 9, 2009
    Messages:
    133
    Likes Received:
    0
    : 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. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  8. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    TIMEDIR does look like the most elegant approach proposed thus far.
     
  9. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,191
    Likes Received:
    11
    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.
     
  10. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    That'll give the n most recent in a single directory....
     
  11. Jim Cook

    Joined:
    May 20, 2008
    Messages:
    604
    Likes Received:
    0
    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:




    --
    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.
     
  12. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,191
    Likes Received:
    11
    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:



    samintz)---


    --
    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. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,028
    Likes Received:
    0
    Scott,

    Why does your lines wrap so early? Are you posting thru the website or what email client?
    ----- Original Message -----
    From: samintz
    To: CSGalloway@nc.rr.com
    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.
     
  14. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,191
    Likes Received:
    11
    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: CSGalloway@nc.rr.com
    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:

    samintz)---


    Quote:


    --
    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.
     
  15. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    You can't use WordStar as your editor? Or SpeedScript, or whatever?
     
  16. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,191
    Likes Received:
    11
    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. Steve Pitts

    Joined:
    Jul 7, 2008
    Messages:
    159
    Likes Received:
    0
    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. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    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-----
    
    
     
  19. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    And here 'tis: Sift Plugin
    Won't work in TCC/LE, which doesn't support arrays.
     
  20. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  21. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    /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.

    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.

    Or perhaps allow args in any order, but require a double percent sign before the array name?
     
  22. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  23. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    On second thought, rather than multiple arguments, wouldn't it make more sense just to (correctly) support include lists?
     
  24. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  25. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    I'm putting up a radically rewritten build, which not only addresses some of Steve's suggestions, but also seriously speeds up the process for very large arrays. Please beat on it!
     
  26. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Currently the download v0.30.0 is still posted, not the documented v0.50.0. Or do I need to purge my browser cache?
     
  27. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    It's definitely 0.50. A forced refresh ought to do it; or purge the cache if that doesn't work.
     
  28. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,028
    Likes Received:
    0
    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: CSGalloway@nc.rr.com
    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.
     
  29. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,312
    Likes Received:
    39
    I meant the browser cache.
     
  30. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    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.
     

Share This Page