Expanded and structurized scripts.

This commit is contained in:
serialexperiments0815 2025-10-18 16:45:58 +02:00
commit fbcf753965
33 changed files with 158 additions and 0 deletions

View file

@ -0,0 +1,14 @@
# Deletes all objects older than 30 days inside the folder.
# -WhatIf Parameter was chosen for Remove-Item to remove the necessity for file -recreation
# Should creation of an file older than 30 days for testing purposes be necessary, run this script:
# $file = "./testing.txt"
# New-Item -Path $file -ItemType File -Force
# $oldDate = (Get-Date).AddDays(-31)
# (Get-Item $file).LastWriteTime = $oldDate
# (Get-Item $file).LastAccessTime = $oldDate
Get-ChildItem ".\" -Recurse |
Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} |
Remove-Item -Force -WhatIf

View file

@ -0,0 +1,5 @@
# Export all file and folder path to folderFileList.csv
# Select-Object FullName property was chosen to only export the full path.
Get-ChildItem -Path "./" -Recurse |
Select-Object -Property FullName |
Export-Csv -Path "./folderFileList.csv" -NoTypeInformation

View file

@ -0,0 +1,25 @@
# Assign all relevant file-extensions to arrays to easily filter through them during a for-loop
# This approach was choosen for its simplicity and visibility
[String[]]$videoFormat = "mp4", "mkv", "mov", "avi", "wmv", "flv", "webm", "mpeg", "mpg", "m4v", "3gp", "ogv", "ts", "vob"
[String[]]$pictureFormat = "jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "webp", "heic", "heif", "raw", "cr2", "nef", "arw", "svg", "ico"
[String[]]$documentFormat = "pdf", "doc", "docx", "odt", "rtf", "txt", "csv", "xls", "xlsx", "ods", "ppt", "pptx", "odp", "md", "html", "xml"
$filesInFolder = Get-ChildItem -Path "./" -File
foreach($file in $filesInFolder){
$extension = $file.Extension.TrimStart('.').ToLower()
if ($videoFormat -contains $extension){
Move-Item -Path $file.FullName -Destination "./videos/$($file.Name)"
}
elseif ($pictureFormat -contains $extension) {
Move-Item -Path $file.FullName -Destination "./pictures/$($file.Name)"
}
elseif ($documentFormat -contains $extension) {
Move-Item -Path $file.FullName -Destination "./documents/$($file.Name)"
}
}

View file

@ -0,0 +1,8 @@
# File searches for txt files and replaces specified string.
$textFiles = Get-ChildItem -Path "./" -Filter *.txt
$searchText = 'this text is false'
$replaceText = 'this text is true'
foreach($textFile in $textFiles){
(Get-Content $textFile) -replace $searchText, $replaceText | Set-Content $textFile
}

View file

@ -0,0 +1,2 @@
this text is false

View file

@ -0,0 +1,2 @@
this text is false

View file

@ -0,0 +1,7 @@
# Copy 'important' folder to 'safe' location
# Get-ChildItem -Filter parameter was deemed insufficient and replaced by -Directory | Where-Object
# As the -Filter parameter only matches folders at current level, not recursively in all subfolders.
$nameOfFolder = "important"
$directionOfFolder = Get-ChildItem -Path "./" -Recurse -Directory | Where-Object { $_.Name -eq $nameOfFolder }
Copy-Item -Path $directionOfFolder.FullName -Destination (Join-Path "./safe/" $directionOfFolder.Name) -Recurse -Force

View file

@ -0,0 +1 @@
important