Last active
September 3, 2015 14:55
-
-
Save brunomlopes/165857 to your computer and use it in GitHub Desktop.
Simple powershell script to archive a downloads folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$base_downloads_dir = "S:\downloads\" | |
$base_archive_dir = "S:\downloads\archive" | |
if(-not (Test-Path $base_archive_dir)) { | |
[void] (mkdir $base_archive_dir) | |
} | |
$to_archive_files = get-childitem $base_downloads_dir | ? { $_.Name -ne "archive" -and $_.CreationTime -lt (Get-Date).AddDays(-1) } | |
foreach($to_archive in $to_archive_files){ | |
$name = $to_archive.Name | |
$i = 1 | |
while ( Test-Path "$base_archive_dir\$($name)" ) { | |
$name = "$($to_archive.BaseName) ($i)$($to_archive.Extension)" | |
$i+=1; | |
} | |
echo "Moving $($to_archive.FullName) to $base_archive_dir\$name" | |
Move-Item "$($to_archive.FullName)" "$base_archive_dir\$name" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment