How do I efficiently pull up the most recently edited .TXT files?

3

Using Windows is there a command-line string I can execute to show the most recently edited notepad files?

Many times, I don't know the name of the file I need... but I know that I edited it within the last 3 days. What's an efficient way I can perform such an operation in Windows?

Adel

Posted 2019-12-09T16:14:49.800

Reputation: 401

Editor's history must show the names of the files edited last. – Akina – 2019-12-09T16:47:21.873

@PimpJuiceIT - they may exist in subfolders as well – Adel – 2019-12-09T16:51:47.543

@Akina - ok I see, so perhaps Notepad doesn't show the names of those files ? – Adel – 2019-12-09T16:52:19.743

On Windows 10 Right-Click on the Notepad icon on QuickLaunch pane shows last edited files list. Or you may use alternative text editor - for example, NPP may remember up to 99 last files. – Akina – 2019-12-09T17:17:47.607

@PimpJuiceIT - This gave me an error : .Split : The term '.Split' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:8

  • $z| % {_.Split(",")[1]};
  •    ~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (_.Split:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException
  • < – Adel – 2019-12-09T17:55:36.603

@PimpJuiceIT - I'll play with this code , I see what ur trying to do – Adel – 2019-12-09T18:01:04.477

@PimpJuiceIT - its 5.1.18362.145 – Adel – 2019-12-09T18:07:36.863

Answers

3

Easily get the most recent modified files recursively in order

One way to do this with PowerShell would be to...

  1. Use Get-ChildItem to get a recursive list of files .txt extensions

  2. Pipe that through to a ForEach-Object loop and use grouping and subexpression operators to return the LastWriteTime property value followed by a comma and the full path file name of each file—sort that in descending order by the LastWriteTime value.

  3. With the #1 and #2 result being a variable, pipe that over in a loop to Split(), with the comma being the delimiter, and return only the 2nd index (i.e. [1]) of the iterated value and retain the descending order of the time stamp but return only the full path file names.

PowerShell

$Src = "C:\YourFolder";
$z = (Get-Childitem -Path $Src -include "*.txt" -File -Recurse | % {"$($_.LastWriteTime), $($_.FullName)"}) | Sort-Object -Descending;
$z | % {$_.Split(",")[1]};

Example Structure

C:\Users\user\Desktop\Dir\A
C:\Users\user\Desktop\Dir\B
C:\Users\user\Desktop\Dir\Test.txt
C:\Users\user\Desktop\Dir\Test2.txt
C:\Users\user\Desktop\Dir\Test3.txt
C:\Users\user\Desktop\Dir\A\2019-07-29 22_18_52-Inquiries.txt
C:\Users\user\Desktop\Dir\A\blah.txt
C:\Users\user\Desktop\Dir\A\Test4.txt
C:\Users\user\Desktop\Dir\B\FLLtest.txt
C:\Users\user\Desktop\Dir\B\FLLtest2.txt

Example Command Output (with date time)

PS C:\Users\user> (Get-Childitem -Path $Src -include "*.txt" -File -Recurse | % {"$($_.LastWriteTime), $($_.FullName)"}) | Sort-Object -Descending;
12/09/2019 18:14:09, C:\Users\user\Desktop\Dir\A\Test4.txt
12/08/2019 20:27:26, C:\Users\user\Desktop\Dir\Test2.txt
12/03/2019 23:55:50, C:\Users\user\Desktop\Dir\Test3.txt
11/02/2019 12:51:35, C:\Users\user\Desktop\Dir\B\FLLtest2.txt
11/02/2019 12:49:09, C:\Users\user\Desktop\Dir\B\FLLtest.txt
07/29/2019 22:38:33, C:\Users\user\Desktop\Dir\A\blah.txt
07/29/2019 22:38:17, C:\Users\user\Desktop\Dir\A\2019-07-29 22_18_52-Inquiries.txt
06/21/2019 23:38:01, C:\Users\user\Desktop\Dir\Test.txt

Example Full Script Output

 C:\Users\user\Desktop\Dir\A\Test4.txt
 C:\Users\user\Desktop\Dir\Test2.txt
 C:\Users\user\Desktop\Dir\Test3.txt
 C:\Users\user\Desktop\Dir\B\FLLtest2.txt
 C:\Users\user\Desktop\Dir\B\FLLtest.txt
 C:\Users\user\Desktop\Dir\A\blah.txt
 C:\Users\user\Desktop\Dir\A\2019-07-29 22_18_52-Inquiries.txt
 C:\Users\user\Desktop\Dir\Test.txt

Supporting Resources

Pimp Juice IT

Posted 2019-12-09T16:14:49.800

Reputation: 29 425

1Getting the TOP x records or getting more granular or specific is just a trivial matter so, if you have questions, just let me know as a potential adjustment is simply enough. – Pimp Juice IT – 2019-12-10T04:10:16.217

0


This is simple option to do this in / or command line for local/folder list only:


/o:d = order by date (old first) || is the same /od
/o-d = order by date (reverse -) || is the same /o:-d
/b   = basic out put (name only) 
/s   = recursively

:: - - - - - - - - - - - - - - - - - - - - - - - - - - ::

rem./  you can use any options...

dir /o:-d /b /s
dir /o-d /b /s 
dir /o-d/b/s
dir/o-d/b/s

It Wasn't Me

Posted 2019-12-09T16:14:49.800

Reputation: 851