Updated the cd-*.ps1 scripts

This commit is contained in:
Markus Fleschutz 2025-03-27 12:22:40 +01:00
parent 37fb994ed5
commit ea112a42bd
28 changed files with 135 additions and 82 deletions

View File

@ -15,12 +15,12 @@
try { try {
$path = Resolve-Path "~/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup" $path = Resolve-Path "~/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"
if (-not(Test-Path "$path" -pathType container)) { if (-not(Test-Path "$path" -pathType container)) {
throw "Autostart folder at 📂$path doesn't exist (yet)" throw "No autostart folder at 📂$path"
} }
Set-Location "$path" Set-Location "$path"
"📂$path" "📂$path"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -16,16 +16,16 @@ try {
if ($IsLinux) { throw "Sorry, Windows only" } if ($IsLinux) { throw "Sorry, Windows only" }
[string]$path = Resolve-Path -Path "~" [string]$path = Resolve-Path -Path "~"
if (!(Test-Path "$path" -pathType container)) { throw "Home directory at $path doesn't exist (yet)" } if (!(Test-Path "$path" -pathType container)) { throw "No home directory at $path" }
$path += "\AppData\Local\CrashDumps" $path += "\AppData\Local\CrashDumps"
if (!(Test-Path "$path" -pathType container)) { throw "Crashdumps directory at $path doesn't exist (yet)" } if (!(Test-Path "$path" -pathType container)) { throw "No crashdumps folder at $path" }
Set-Location "$Path" Set-Location "$Path"
$files = Get-ChildItem $path -attributes !Directory $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory $folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -18,13 +18,13 @@ try {
} else { } else {
$path = [Environment]::GetFolderPath('DesktopDirectory') $path = [Environment]::GetFolderPath('DesktopDirectory')
} }
if (Test-Path "$path" -pathType container) { if (-not(Test-Path "$path" -pathType container)) {
throw "No desktop folder at 📂$path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" "📂$path"
exit 0 # success exit 0 # success
}
throw "User's desktop folder at 📂$path doesn't exist (yet)"
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -19,7 +19,7 @@ try {
$path = [Environment]::GetFolderPath('MyDocuments') $path = [Environment]::GetFolderPath('MyDocuments')
} }
if (-not(Test-Path "$path" -pathType container)) { if (-not(Test-Path "$path" -pathType container)) {
throw "Documents folder at 📂$path doesn't exist (yet)" throw "No documents folder at 📂$path"
} }
Set-Location "$path" Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory $files = Get-ChildItem $path -attributes !Directory
@ -27,6 +27,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -19,7 +19,7 @@ try {
$path = (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path $path = (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path
} }
if (-not(Test-Path "$path" -pathType container)) { if (-not(Test-Path "$path" -pathType container)) {
throw "User's downloads folder at 📂$path doesn't exist (yet)" throw "No downloads folder at 📂$path"
} }
Set-Location "$path" Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory $files = Get-ChildItem $path -attributes !Directory
@ -27,6 +27,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -14,7 +14,9 @@
try { try {
$path = Resolve-Path "~/Dropbox" $path = Resolve-Path "~/Dropbox"
if (-not(Test-Path "$path" -pathType container)) { throw "No Dropbox folder at 📂$path - is Dropbox installed?" } if (-not(Test-Path "$path" -pathType container)) {
throw "No Dropbox folder at 📂$path - is Dropbox installed?"
}
Set-Location "$path" Set-Location "$path"
"📂$path" "📂$path"
exit 0 # success exit 0 # success

View File

@ -19,12 +19,12 @@ try {
$path = Resolve-Path "$env:WINDIR\System32\drivers\etc" $path = Resolve-Path "$env:WINDIR\System32\drivers\etc"
} }
if (-not(Test-Path "$path" -pathType container)) { if (-not(Test-Path "$path" -pathType container)) {
throw "/etc directory at 📂$path doesn't exist (yet)" throw "No /etc directory at 📂$path"
} }
Set-Location "$path" Set-Location "$path"
"📂$path" "📂$path"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -15,12 +15,12 @@
try { try {
$path = [Environment]::GetFolderPath('Fonts') $path = [Environment]::GetFolderPath('Fonts')
if (-not(Test-Path "$path" -pathType container)) { if (-not(Test-Path "$path" -pathType container)) {
throw "Fonts folder at 📂$path doesn't exist (yet)" throw "No fonts folder at 📂$path"
} }
Set-Location "$path" Set-Location "$path"
"📂$path" "📂$path"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -14,13 +14,13 @@
try { try {
$path = Resolve-Path "~" $path = Resolve-Path "~"
if (-not(Test-Path "$path" -pathType container)) { throw "Home folder at $path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) { throw "No home directory at $path" }
Set-Location "$path" Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory $folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the Jenkins home directory. This PowerShell script changes the working directory to the Jenkins home directory.
.EXAMPLE .EXAMPLE
PS> ./cd-jenkins PS> ./cd-jenkins
📂C:\Users\Markus\.jenkins 📂C:\Users\Markus\.jenkins entered (has 2 files and 21 folders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -21,7 +21,9 @@ try {
throw "No Jenkins home directory found - is Jenkins installed?" throw "No Jenkins home directory found - is Jenkins installed?"
} }
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error: $($Error[0])" "⚠️ Error: $($Error[0])"

View File

@ -24,6 +24,6 @@ try {
"📂$path" "📂$path"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's music folder. This PowerShell script changes the working directory to the user's music folder.
.EXAMPLE .EXAMPLE
PS> ./cd-music PS> ./cd-music
📂C:\Users\Markus\Music entered (has 0 files and 3 folders) 📂C:\Users\Markus\Music entered (has 0 files and 3 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -19,14 +19,14 @@ try {
$path = [Environment]::GetFolderPath('MyMusic') $path = [Environment]::GetFolderPath('MyMusic')
} }
if (-not(Test-Path "$path" -pathType container)) { if (-not(Test-Path "$path" -pathType container)) {
throw "User's music folder at 📂$path doesn't exist (yet)" throw "No music folder at 📂$path"
} }
Set-Location "$path" Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory $folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's NextCloud folder. This PowerShell script changes the working directory to the user's NextCloud folder.
.EXAMPLE .EXAMPLE
PS> ./cd-nextcloud PS> ./cd-nextcloud
📂C:\Users\Markus\NextCloud 📂C:\Users\Markus\NextCloud entered (has 2 files and 3 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -14,9 +14,13 @@
try { try {
$path = Resolve-Path "~/NextCloud" $path = Resolve-Path "~/NextCloud"
if (-not(Test-Path "$path" -pathType container)) { throw "No NextCloud folder at 📂$path - is NextCloud installed?" } if (-not(Test-Path "$path" -pathType container)) {
throw "No NextCloud folder at $path - is NextCloud installed?"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error: $($Error[0])" "⚠️ Error: $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's OneDrive folder. This PowerShell script changes the working directory to the user's OneDrive folder.
.EXAMPLE .EXAMPLE
PS> ./cd-onedrive PS> ./cd-onedrive
📂C:\Users\Markus\OneDrive 📂C:\Users\Markus\OneDrive entered (has 2 files and 3 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -14,9 +14,13 @@
try { try {
$path = Resolve-Path "~/OneDrive" $path = Resolve-Path "~/OneDrive"
if (-not(Test-Path "$path" -pathType container)) { throw "No OneDrive folder at 📂$path - is OneDrive installed?" } if (-not(Test-Path "$path" -pathType container)) {
throw "No OneDrive folder at $path - is OneDrive installed?"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error: $($Error[0])" "⚠️ Error: $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's pictures folder. This PowerShell script changes the working directory to the user's pictures folder.
.EXAMPLE .EXAMPLE
PS> ./cd-pics PS> ./cd-pics
📂C:\Users\Markus\Pictures entered (has 7 files and 0 folders) 📂C:\Users\Markus\Pictures entered (has 7 files and 0 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -18,13 +18,15 @@ try {
} else { } else {
$path = [Environment]::GetFolderPath('MyPictures') $path = [Environment]::GetFolderPath('MyPictures')
} }
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No pictures folder at $path"
}
Set-Location "$path" Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory $folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the Public folder. This PowerShell script changes the working directory to the Public folder.
.EXAMPLE .EXAMPLE
PS> ./cd-public PS> ./cd-public
📂C:\Users\Public 📂C:\Users\Public entered (has 2 files and 3 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -18,11 +18,15 @@ try {
} else { } else {
$path = Resolve-Path "~/../Public" $path = Resolve-Path "~/../Public"
} }
if (-not(Test-Path "$path" -pathType container)) { throw "Public folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No public folder at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the 'recent' folder. This PowerShell script changes the working directory to the 'recent' folder.
.EXAMPLE .EXAMPLE
PS> ./cd-recent PS> ./cd-recent
📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent 📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Recent entered (has 2 files and 3 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -15,10 +15,12 @@
try { try {
$path = [Environment]::GetFolderPath('Recent') $path = [Environment]::GetFolderPath('Recent')
if (-not(Test-Path "$path" -pathType container)) { if (-not(Test-Path "$path" -pathType container)) {
throw "Recent folder at 📂$path doesn't exist (yet)" throw "No recent folder at $path"
} }
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's recycle bin folder. This PowerShell script changes the working directory to the user's recycle bin folder.
.EXAMPLE .EXAMPLE
PS> ./cd-recycle-bin PS> ./cd-recycle-bin
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 entered (has 2 files and 0 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -24,11 +24,15 @@ try {
} else { } else {
$path = "C:\`$Recycle.Bin\$(GetCurrentUserSID)" $path = "C:\`$Recycle.Bin\$(GetCurrentUserSID)"
} }
if (-not(Test-Path "$path" -pathType container)) { throw "Recycle bin folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No recycle bin folder at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -20,6 +20,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -33,6 +33,6 @@ try {
"📂$path entered (has $($files.Count) files and $($folders.Count) folders)" "📂$path entered (has $($files.Count) files and $($folders.Count) folders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -14,12 +14,14 @@
try { try {
$path = Resolve-Path "$PSScriptRoot" $path = Resolve-Path "$PSScriptRoot"
if (-not(Test-Path "$path" -pathType container)) { throw "PowerShell scripts folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No PowerShell scripts folder at 📂$path"
}
Set-Location "$path"
$files = Get-ChildItem $path -attributes !Directory $files = Get-ChildItem $path -attributes !Directory
"📂$path entered (has $($files.Count) scripts)" "📂$path entered (has $($files.Count) scripts)"
Set-Location "$path"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's secure shell (SSH) folder. This PowerShell script changes the working directory to the user's secure shell (SSH) folder.
.EXAMPLE .EXAMPLE
PS> ./cd-ssh.ps1 PS> ./cd-ssh.ps1
📂C:\Users\Markus\.ssh 📂C:\Users\Markus\.ssh entered (has 4 files)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -14,10 +14,13 @@
try { try {
$path = "~/.ssh" $path = "~/.ssh"
if (-not(Test-Path "$path" -pathType container)) { throw "Your secure shell (SSH) folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No secure shell (SSH) folder at $path"
}
$path = Resolve-Path "$path" $path = Resolve-Path "$path"
Set-Location "$path" Set-Location "$path"
"📂$Path" $files = Get-ChildItem $path -attributes !Directory
"📂$path entered (has $($files.Count) files)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error: $($Error[0])" "⚠️ Error: $($Error[0])"

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the temporary folder. This PowerShell script changes the working directory to the temporary folder.
.EXAMPLE .EXAMPLE
PS> ./cd-temp PS> ./cd-temp
📂C:\Users\Markus\AppData\Local\Temp 📂C:\Users\Markus\AppData\Local\Temp (has 2 files and 3 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -21,11 +21,15 @@ function GetTempDir {
try { try {
$path = GetTempDir $path = GetTempDir
if (-not(Test-Path "$path" -pathType container)) { throw "Temporary folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) { throw
"No temporary folder at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the templates folder. This PowerShell script changes the working directory to the templates folder.
.EXAMPLE .EXAMPLE
PS> ./cd-templates PS> ./cd-templates
📂/home/Markus/Templates 📂/home/Markus/Templates entered (has 3 files and 0 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -18,11 +18,15 @@ try {
} else { } else {
$path = [Environment]::GetFolderPath('Templates') $path = [Environment]::GetFolderPath('Templates')
} }
if (-not(Test-Path "$path" -pathType container)) { throw "Templates folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No templates folder at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's trash folder. This PowerShell script changes the working directory to the user's trash folder.
.EXAMPLE .EXAMPLE
PS> ./cd-trash PS> ./cd-trash
📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 📂C:\$Recycle.Bin\S-1-5-21-123404-23309-294260-1001 entered (has 4 files and 0 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -24,11 +24,15 @@ try {
} else { } else {
$path = "C:\`$Recycle.Bin\$(GetCurrentUserSID)" $path = "C:\`$Recycle.Bin\$(GetCurrentUserSID)"
} }
if (-not(Test-Path "$path" -pathType container)) { throw "Trash folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No trash folder at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the users directory. This PowerShell script changes the working directory to the users directory.
.EXAMPLE .EXAMPLE
PS> ./cd-users PS> ./cd-users
📂C:\Users 📂C:\Users entered (has 0 files and 4 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -14,11 +14,15 @@
try { try {
$path = Resolve-Path "~/.." $path = Resolve-Path "~/.."
if (-not(Test-Path "$path" -pathType container)) { throw "Users directory at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No users directory at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the user's videos folder. This PowerShell script changes the working directory to the user's videos folder.
.EXAMPLE .EXAMPLE
PS> ./cd-videos PS> ./cd-videos
📂C:\Users\Markus\Videos 📂C:\Users\Markus\Videos entered (has 3 files and 0 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -18,11 +18,15 @@ try {
} else { } else {
$path = [Environment]::GetFolderPath('MyVideos') $path = [Environment]::GetFolderPath('MyVideos')
} }
if (-not(Test-Path "$path" -pathType container)) { throw "Videos folder at 📂$path doesn't exist (yet)" } if (-not(Test-Path "$path" -pathType container)) {
throw "No videos folder at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }

View File

@ -5,7 +5,7 @@
This PowerShell script changes the working directory to the Windows directory. This PowerShell script changes the working directory to the Windows directory.
.EXAMPLE .EXAMPLE
PS> ./cd-windows PS> ./cd-windows
📂C:\Windows 📂C:\Windows entered (has 7 files and 42 subfolders)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -14,11 +14,15 @@
try { try {
$path = Resolve-Path "$env:WINDIR" $path = Resolve-Path "$env:WINDIR"
if (-not(Test-Path "$path" -pathType container)) { throw "Windows directory at 📂$path doesn't exist" } if (-not(Test-Path "$path" -pathType container)) {
throw "No Windows directory at $path"
}
Set-Location "$path" Set-Location "$path"
"📂$path" $files = Get-ChildItem $path -attributes !Directory
$folders = Get-ChildItem $path -attributes Directory
"📂$path entered (has $($files.Count) files and $($folders.Count) subfolders)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error: $($Error[0])"
exit 1 exit 1
} }