Count all files older than specific date??

by tommls at 2013-01-09 08:29:51

Plenty of scripts out there for deleting files older than N days. :slight_smile:

I need to count how many files in many directories are older than a specific date (creation and modified).

e.g. for d:\folder, review all files, output #### files older than 1/1/2008.

Found code here:
http://www.marcvalk.net/2012/06/powersh … e-mistake/
[array]$OldestFileImport = get-childitem d: *.XML | where-object {$.LastWriteTime -le [datetime]::today}
$OldestFileImport.count

I can use . instead of *.xml but how do I change the ‘today’ to be my desired date??
How do I review multiple folders??

Thank you, Tom
by tommls at 2013-01-09 09:25:56
The blogger gave me this code:
$date=12/31/2006
$OldestFileImport = get-childitem “ ” . | where-object {$
.LastWriteTime -le $date}
$OldestFileImport.count
Any suggestions how I can make it count multiple folders??
e.g. run this script for all folders in D:?? and output a per-folder count??
Thank you, Tom
by DonJ at 2013-01-09 11:28:10
You can use the -recurse parameter of Get-ChildItem to make it include subfolders. However, if the goal is to provide a per-folder count, then you’re not going to be able to do this with a simple one-liner. It’s going to be a more complicated script, and you’ll probably have to manually write a recursion routine. -Ish.

Are you running this in PowerShell v2 or v3? It makes a bit of a difference in the example I can show you.

Are you just getting started with PowerShell? That’ll drive what kind of example I come up with, as well. I want to show you something you can understand and modify to meet your needs, not something totally over your head.
by DonJ at 2013-01-09 13:46:44
Closing thread - asker has this same question open on viewtopic.php?f=2&t=1019&p=4249#p4249.