mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-25 06:24:14 +02:00
Updated cd-public.ps1 and cd-screenshots.ps1
This commit is contained in:
parent
de29c358db
commit
5ad6815eba
@ -1,11 +1,11 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Sets the working directory to the Public folder
|
Sets the working dir to the Public folder
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script changes the working directory to the Public folder.
|
This PowerShell script sets the current working directory to the Public folder.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-public
|
PS> ./cd-public.ps1
|
||||||
📂C:\Users\Public entered (has 2 files and 3 subfolders)
|
📂C:\Users\Public with 2 files and 3 folders entered.
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -14,17 +14,20 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if ($IsLinux) {
|
if ($IsLinux) {
|
||||||
|
if (-not(Test-Path "~/Public" -pathType container)) {
|
||||||
|
throw "No 'Public' folder in your home directory yet"
|
||||||
|
}
|
||||||
$path = Resolve-Path "~/Public"
|
$path = Resolve-Path "~/Public"
|
||||||
} else {
|
} else {
|
||||||
$path = Resolve-Path "~/../Public"
|
if (-not(Test-Path "~/../Public" -pathType container)) {
|
||||||
|
throw "No 'Public' folder yet"
|
||||||
}
|
}
|
||||||
if (-not(Test-Path "$path" -pathType container)) {
|
$path = Resolve-Path "~/../Public"
|
||||||
throw "No public 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) subfolders)"
|
"📂$path with $($files.Count) files and $($folders.Count) folders entered."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Sets the working directory to the user's screenshots folder
|
Sets the working dir to the user's screenshots folder
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script changes the working directory to the user's screenshots folder.
|
This PowerShell script sets the current working directory to the user's screenshots folder.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./cd-screenshots
|
PS> ./cd-screenshots.ps1
|
||||||
📂C:\Users\Markus\Pictures\Screenshots (has 7 files and 0 folders)
|
📂C:\Users\Markus\Pictures\Screenshots with 7 files and 0 folders entered.
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
function GetScreenshotsFolder {
|
function GetScreenshotsFolder {
|
||||||
if ($IsLinux) {
|
if ($IsLinux) {
|
||||||
|
if (-not(Test-Path "~/Pictures" -pathType container)) { throw "No 'Pictures' folder in your home directory yet" }
|
||||||
$path = "~/Pictures"
|
$path = "~/Pictures"
|
||||||
if (-not(Test-Path "$path" -pathType container)) { throw "Pictures folder at $path doesn't exist (yet)" }
|
|
||||||
if (Test-Path "$path/Screenshots" -pathType container) { $path = "$path/Screenshots" }
|
if (Test-Path "$path/Screenshots" -pathType container) { $path = "$path/Screenshots" }
|
||||||
} 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" }
|
||||||
if (Test-Path "$path\Screenshots" -pathType container) { $path = "$path\Screenshots" }
|
if (Test-Path "$path\Screenshots" -pathType container) { $path = "$path\Screenshots" }
|
||||||
}
|
}
|
||||||
return $path
|
return $path
|
||||||
@ -30,7 +30,7 @@ try {
|
|||||||
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 with $($files.Count) files and $($folders.Count) folders entered."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user