15

In Linux I know this command to find and list the latest modified files in a directory with all its subdirectories.

find /var/www/ -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2- | head

Is there a Windows CLI equivalent?

4
  • are you looking for only modified files? Or are you looking at all files?
    – Keltari
    Feb 2, 2013 at 17:25
  • 1
    I'm sure PowerShell can do this far more easily than batch, but if you absolutely must use the latter... Try dir /a-d /o-d /tw /s (show files only, order by date descending, use last write time for sorting, recurse into subdirs). However this will list all files. To limit the list to n latest modified files only, use dbenham's brilliant solution here.
    – Karan
    Feb 2, 2013 at 17:43
  • A couple of comments on the Linux command: (1) Instead of -exec, you might want to consider xargs. (2) If you, as you say, want to sort an entire directory (sub)tree by modification date (and then look at the newest N), then what you have is reasonable. But if you can get the information you need by finding all files modified in the last N days, look at find … -mtime …. Feb 2, 2013 at 20:41
  • 2
    To add to my previous comment, you can also look into forfiles /s /d +<date>.
    – Karan
    Feb 2, 2013 at 23:22

3 Answers 3

24

PowerShell 2.0

Latest 10 changed files

Dir C:\folder -r | ? {! $_.PSIsContainer} | sort LastWriteTime | select -last 10

Changed files since given date

Dir C:\folder -r | ? {! $_.PSIsContainer -AND $_.lastwritetime -ge '04/18/14'} 

Read more on http://ss64.com/ps/

1
  • If you just want to show the directories with modified files, do this. Dir d:\sftp -r | ? {! $_.PSIsContainer -AND $_.lastwritetime -ge '05/25/2018'} |findstr Directory
    – Rob
    Jun 15, 2018 at 12:05
0
dir c:\windows\ /aa /s /O-D

Lists all the files with the archive attribute set (modified) in the c:\windows folder and all its subfolders by date (newest first)

Edit: This method will only work if you clear the archive bits at some point or the list will just grow and grow.

3
  • 1
    What does the Archive attribute have to do with recently changed files?
    – Karan
    Feb 2, 2013 at 17:10
  • 1
    Everything. Any file that gets changed gets the archive attribute set by the OS. Thats how backup programs know that a file has changed and needs to be backed up.
    – Keltari
    Feb 2, 2013 at 17:15
  • 3
    Your edit is extremely important. Files with +A already will see no change. Why not find some way to do this based on Date Modified?
    – Karan
    Feb 2, 2013 at 17:24
0

Take a look at MT Directory Changes Watcher. May be it is right for your needs.

Program watches for file changes in particular directory (Watch directory) and then copies changed files to another folder (Mirror directory) saving directory structure. This can be very useful when you have local copy of remote site and want to upload only files, changed locally after last upload.

http://mito-team.com/projects/dcw

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .