I ran across this code in another post that almost does what I need, but can\'t figure out how to modify it to look for specific file types, i.e. *.bak, .txt, etc. I\'m
Here's a simple PowerShell script to move many files from a directory into a structured directory by year, month and day. This is very fast, I had over 500K files.
$listofFiles = [System.IO.Directory]::EnumerateFiles("D:\LotsOfFiles","*.*","TopDirectoryOnly")
$listofFiles |% {
$file = New-Object System.IO.FileInfo($_)
$date = Get-Date ($file.CreationTime)
$filepath = ("{0}\{1:00}\{2:00}-{3}\{4:00}\" -f "D:\LotsOfFiles", $date.year,
$date.month, $date.toString("MMM"), $date.day)
Write-Output ("Move: {0} to {1}" -f $file.Fullname, $filepath)
if (! (Test-Path $filepath)) {
new-item -type Directory -path $filepath
}
move-item $file $filepath
}
This probably can be improved but it works.