diff --git a/functions/New-OrganiseDownloads.ps1 b/functions/New-OrganiseDownloads.ps1 new file mode 100644 index 0000000..377a9f6 --- /dev/null +++ b/functions/New-OrganiseDownloads.ps1 @@ -0,0 +1,24 @@ +# gitea.RdzeN.net +# Work with download folder - organise by date +# + +$downloadsPath = "$env:userprofile\Downloads" + +# Getting today's date and calculating yesterday's date +$today = Get-Date +$yesterday = $today.AddDays(-1).ToString("yyyy-MM-dd") + +# Path to the folder for files from yesterday +$yesterdayFolder = Join-Path -Path $downloadsPath -ChildPath $yesterday + +# If the folder for yesterday's files doesn't exist, it is created +if (-not (Test-Path -Path $yesterdayFolder)) { + New-Item -Path $yesterdayFolder -ItemType Directory | Out-Null +} + +# Getting all files from the Downloads folder, older than today +$filesToMove = Get-ChildItem -Path $downloadsPath | Where-Object {$_.LastWriteTime -lt $today -and $_.Name -notmatch '^\d{4}-\d{2}-\d{2}$' +} + +# Moving files to the folder from yesterday +$filesToMove | Move-Item -Destination $yesterdayFolder