moving files into folders (yyyy-mm)
$StartInPath = "c:\Anoop\test"
$DirectoryList = Get-ChildItem $StartInPath -Directory -Recurse | Where-Object {
($_.FullName) -notmatch "archived" } | Where-Object {
($_.GetFiles().Count) -ne 0}
#Write-Output $DirectoryList
foreach ($directory in $DirectoryList) {
$fileList = Get-ChildItem $directory.FullName -File
foreach ($file in $fileList){
$destinationDir = $directory.FullName + "\archived\" + $file.LastWriteTime.Date.ToString('yyyy') + "-" + $file.LastWriteTime.Date.ToString('MM')
Write-Output $destinationDir
if (!(Test-Path $destinationDir))
{
New-Item $destinationDir -type directory
}
Move-Item $file.fullname $destinationDir
}
}
$StartInPath = "c:\Anoop\test"
$DirectoryList = Get-ChildItem $StartInPath -Directory -Recurse | Where-Object {
($_.FullName) -notmatch "archived" } | Where-Object {
($_.GetFiles().Count) -ne 0}
#Write-Output $DirectoryList
foreach ($directory in $DirectoryList) {
$fileList = Get-ChildItem $directory.FullName -File
foreach ($file in $fileList){
$destinationDir = $directory.FullName + "\archived\" + $file.LastWriteTime.Date.ToString('yyyy') + "-" + $file.LastWriteTime.Date.ToString('MM')
Write-Output $destinationDir
if (!(Test-Path $destinationDir))
{
New-Item $destinationDir -type directory
}
Move-Item $file.fullname $destinationDir
}
}