new file: functions/New-OrganiseDownloads.ps1
This commit is contained in:
parent
8d876708b7
commit
5dbda672e0
24
functions/New-OrganiseDownloads.ps1
Normal file
24
functions/New-OrganiseDownloads.ps1
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user