-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanScreenshots
More file actions
35 lines (33 loc) · 1.9 KB
/
Copy pathcleanScreenshots
File metadata and controls
35 lines (33 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Cleans Windows 11 screenshots folder
# checks last modified date on screenshots folder. If it was yesterday, checks if subfolder with yesterday's date exists
# If not, creates it. Pushes all screenshots to that subfolder in either situation
# Meant to optimize the use of snipping tool's auto-saving
#-------------------------------------------
$username = $env:USERNAME # pulls username
$screenshotFolder = "C:\Users\$username\Pictures\Screenshots" # pulls screenshots folder
# get yesterday and today
$yesterday = (Get-Date).AddDays(-1).ToString("yyyy-MM-dd")
$today = (Get-Date).ToString("yyyy-MM-dd")
# get the last modified date of the Screenshots folder
$folderLastModified = (Get-Item $screenshotFolder).LastWriteTime.ToString("yyyy-MM-dd")
# Debug, puts last mod date
Write-Output "Last modified date of Screenshots folder: $folderLastModified"
# Check if the folder was modified yesterday
if ($folderLastModified -eq $yesterday) {
# If the folder was modified yesterday, it's the first login of the day
Write-Output "It’s the first login of the day. Folder was modified yesterday."
# Create the new folder path for yesterday's screenshots
$newFolder = Join-Path -Path $screenshotFolder -ChildPath $yesterday
# Check if the folder for yesterday exists
if (-Not (Test-Path $newFolder)) { # if not exists
New-Item -Path $newFolder -ItemType Directory -Force # write the new path
Write-Output "Folder for yesterday was created: $newFolder" # debug info
} else {
Write-Output "Folder for yesterday already exists: $newFolder" # debug info, this else clause can be removed
}
# gets the path of the subfolder, then moves to it.
Get-ChildItem -Path $screenshotFolder -File | Move-Item -Destination $newFolder
Write-Output "Files moved to $newFolder"
} else {
Write-Output "It’s not the first login of the day. Folder was last modified on $folderLastModified."
}