marexit
asked on
compare lastwritetime to lastaccesstime
hi
am trying to compare 500+ files in a directory: say the files were last written to at 0700, but only about 200 have been accessed since (we download all these files everyday and am trying to weed out the ones nobody uses - but of course no one can give me a concrete answer).
so what i want to do is compare the write time and access time so that i can see which files have been accessed.
what i have so far is this (not really querying C:\ - just an example):
get-ChildItem "C:\" | ForEach-Object {
$test = New-TimeSpan ($_.Lastaccesstime) $($_.lastwritetime)
if ($test.minutes -gt '5'){
echo $_.name
}}
...but this doesnt work. please help!
thanks
am trying to compare 500+ files in a directory: say the files were last written to at 0700, but only about 200 have been accessed since (we download all these files everyday and am trying to weed out the ones nobody uses - but of course no one can give me a concrete answer).
so what i want to do is compare the write time and access time so that i can see which files have been accessed.
what i have so far is this (not really querying C:\ - just an example):
get-ChildItem "C:\" | ForEach-Object {
$test = New-TimeSpan ($_.Lastaccesstime) $($_.lastwritetime)
if ($test.minutes -gt '5'){
echo $_.name
}}
...but this doesnt work. please help!
thanks
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
hey thanks for your input. think learnctx is closer to what i need.
not looked at this for ages, so sorry its taken so long to get back to you. just realised the lastwritetime wasnt modified at the time of download (we download these 500 files daily). so i'm wondering if i can change the lastwritetime to an actual time like 0600? we download these files and i want to know if they are being accessed since they were downloaded.
tried setting the end time with get-date but not certain i have the right idea...
any thoughts?
not looked at this for ages, so sorry its taken so long to get back to you. just realised the lastwritetime wasnt modified at the time of download (we download these 500 files daily). so i'm wondering if i can change the lastwritetime to an actual time like 0600? we download these files and i want to know if they are being accessed since they were downloaded.
tried setting the end time with get-date but not certain i have the right idea...
any thoughts?
ASKER
Actually, i think i got it:
GCI "c:\test" | % { if ((New-TimeSpan $('06:00') $_.LastAccessTime).TotalMi nutes -ge 455 {$_.Name }}
points to learnctx for pointing me in the right direction
thanks!! :)
GCI "c:\test" | % { if ((New-TimeSpan $('06:00') $_.LastAccessTime).TotalMi
points to learnctx for pointing me in the right direction
thanks!! :)
You can alter the LastWriteTime attribute.
Get-ChildItem C:\Temp | Foreach-Object {
$_.LastWriteTime = (Get-Date).date.addhours(6)
}
This will take every file in that directory and set the LastWriteTime attribute to 6AM on the day you're running it.
I don't know what you want to do with the logic of this but hopefully you can see how it works?
Open in new window