25 lines
854 B
PowerShell
25 lines
854 B
PowerShell
# 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
|