Return the recent file among other by subdirectory

rated by 0 users
Not Answered This post has 0 verified answers | 15 Replies | 3 Followers

Top 150 Contributor
34 Posts
f.lemanie posted on 02-08-2013 8:12 AM


Some users synchronize their data with synctoy (computer <-> server). I just want to scan folders to find their synctoy files (synctoyxxxxx.dat) and compare its LastWrite Time to compare to de date of the day.

I have 2 problems now:

-1) Synctoy generate several .Dat files. I want to get the more recent. I easily found the command for this but it runs with a single directory. When it exists several subfolders containing .dat files, the script returns just the last one .dat file ! I want to return the more recent .dat file for each folder containing a .dat file and write-host (or log) "more recent file - directory" for each.

-2) How return the number of days beetwen today and the more recents .dat file ?

 This is thmy script below (for 1 subfolder)

$PathFile =  "\\network\Secteur Est"

$File = gci $PathFile -Include synctoy*.dat -Recurse -Force -ErrorAction SilentlyContinue |

            Sort-Object {$_.lastwritetime} -Descending | Select-Object -First 1

I tried a lot of test with Foreach and If but more I try and more it seems to be difficult for me....

Thanks a lot for your answers..

All Replies

Top 10 Contributor
1,821 Posts
Top Contributor

Great, thanks for sharing the final version. Nice to see what you are doing with it!

Page 2 of 2 (16 items) < Previous 1 2 | RSS
Copyright 2012 All rights reserved.