diff --git a/Scripts/cd-users.ps1 b/Scripts/cd-users.ps1 new file mode 100644 index 00000000..891d6cc6 --- /dev/null +++ b/Scripts/cd-users.ps1 @@ -0,0 +1,26 @@ +<# +.SYNOPSIS + Sets the working directory to the users directory +.DESCRIPTION + This PowerShell script changes the working directory to the users directory. +.EXAMPLE + PS> ./cd-users + 📂C:\Users +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +try { + $Path = Resolve-Path "$HOME/.." + if (-not(Test-Path "$Path" -pathType container)) { + throw "Users directory at 📂$Path doesn't exist (yet)" + } + Set-Location "$Path" + "📂$Path" + exit 0 # success +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +} \ No newline at end of file diff --git a/Scripts/list-special-folders.ps1 b/Scripts/list-special-folders.ps1 index e9a9a6c5..2d8be78f 100644 --- a/Scripts/list-special-folders.ps1 +++ b/Scripts/list-special-folders.ps1 @@ -6,9 +6,9 @@ .EXAMPLE PS> ./list-special-folders - Folder Name Folder Path - ----------- ----------- - Home Folder C:\Users\Markus + Folder Name Folder Path + ----------- ----------- + 📂Autostart C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup ... .LINK https://github.com/fleschutz/PowerShell @@ -16,10 +16,6 @@ Author: Markus Fleschutz | License: CC0 #> -function AddLine { param([string]$FolderName, [string]$FolderPath) - New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "$FolderPath" } -} - function GetTempDir { if ("$env:TEMP" -ne "") { return "$env:TEMP" } if ("$env:TMP" -ne "") { return "$env:TMP" } @@ -27,6 +23,10 @@ function GetTempDir { return "C:\Temp" } +function AddLine { param([string]$FolderName, [string]$FolderPath) + New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "$FolderPath" } +} + function ListSpecialFolders { if ($IsLinux) { AddLine "📂Desktop" "$HOME/Desktop" @@ -38,6 +38,8 @@ function ListSpecialFolders { AddLine "📂My Screenshots" "$HOME/Pictures/Screenshots" AddLine "📂My Videos" "$HOME/Videos" AddLine "📂Temporary Folder" "$(GetTempDir)" + $Path = Resolve-Path "$HOME/.." + AddLine "📂Users" "$Path" } else { $Path = Resolve-Path "$HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup" AddLine "📂Autostart" "$Path" @@ -51,6 +53,9 @@ function ListSpecialFolders { AddLine "📂My Screenshots" "$([Environment]::GetFolderPath('MyPictures'))\Screenshots" AddLine "📂My Videos" "$([Environment]::GetFolderPath('MyVideos'))" AddLine "📂Temporary Folder" "$(GetTempDir)" + $Path = Resolve-Path "$HOME/.." + AddLine "📂Users" "$Path" + AddLine "📂Windows" "$([Environment]::GetFolderPath('Windows'))" } }