Move files into sub-folders by YYYYMMDD

# andyb stackoverflow# http://stackoverflow.com/questions/21979360/powershell-how-to-create-directories-based-on-last-modify-date-of-files # script takes files in folderRoot and moves then to folders at the PATH:YYYYMMDDlevel.file $folderRoot=“B:EXCEL”$days = 1 dir $folderRoot|?{(!($_.PsIsContainer)) -and ((get-date)  $_.lastwritetime).totaldays -gt $days }|%{            [string]$year=$([string]$_.lastwritetime.year)            [string]$month=$_.lastwritetime.month            [string]$day=$_.lastwritetime.day            $dir=$folderRoot+$year+“”+$month+“”+$day                         if(!(test-path $dir)){                                     new-item -type container $dir                    }                Write-output $_                 move-item $_.fullname $dir}

Leave a Reply

Your email address will not be published. Required fields are marked *