Skip to content

Instantly share code, notes, and snippets.

@hsimah
Created July 4, 2019 23:38
Show Gist options
  • Save hsimah/6cb3413f805bf6b83f22bb3ef3323905 to your computer and use it in GitHub Desktop.
Save hsimah/6cb3413f805bf6b83f22bb3ef3323905 to your computer and use it in GitHub Desktop.
function Move-ByDate {
param(
$Path = '.',
$Destination
)
Get-ChildItem -Path $Path | ForEach-Object {
$Date = $_.LastWriteTimeUtc | Get-Date -f yyyy.M
$DestPath = Join-Path $Destination $Date
if (-not (Test-Path $DestPath)) {
New-Item -Path $DestPath -ItemType Directory
}
Move-Item -Path $_.FullName -Destination $DestPath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment