File tree Expand file tree Collapse file tree 8 files changed +39
-25
lines changed Expand file tree Collapse file tree 8 files changed +39
-25
lines changed Original file line number Diff line number Diff line change 13
13
#>
14
14
15
15
try {
16
- if ($IsLinux ) {
16
+ if ($IsLinux -or $IsMacOS ) {
17
+ if (-not (Test-Path " ~/Desktop" - pathType container)) {
18
+ throw " No 📂Desktop folder in your home directory yet"
19
+ }
17
20
$path = Resolve-Path " ~/Desktop"
18
21
} else {
19
22
$path = [Environment ]::GetFolderPath(' DesktopDirectory' )
20
- }
21
- if ( -not ( Test-Path " $path " - pathType container)) {
22
- throw " No desktop folder at 📂 $path "
23
+ if ( -not ( Test-Path " $path " - pathType container)) {
24
+ throw " No desktop folder at 📂 $path yet "
25
+ }
23
26
}
24
27
Set-Location " $path "
25
28
" 📂$path "
Original file line number Diff line number Diff line change 13
13
#>
14
14
15
15
try {
16
- if ($IsLinux ) {
16
+ if ($IsLinux -or $IsMacOS ) {
17
+ if (-not (Test-Path " ~/Documents" - pathType container)) {
18
+ throw " No 📂Documents folder in your home directory yet"
19
+ }
17
20
$path = Resolve-Path " ~/Documents"
18
21
} else {
19
22
$path = [Environment ]::GetFolderPath(' MyDocuments' )
20
- }
21
- if ( -not ( Test-Path " $path " - pathType container)) {
22
- throw " No documents folder at 📂 $path "
23
+ if ( -not ( Test-Path " $path " - pathType container)) {
24
+ throw " No documents folder at 📂 $path yet "
25
+ }
23
26
}
24
27
Set-Location " $path "
25
28
$files = Get-ChildItem $path - attributes ! Directory
Original file line number Diff line number Diff line change 15
15
try {
16
16
if ($IsLinux -or $IsMacOS ) {
17
17
if (-not (Test-Path " ~/Downloads" - pathType container)) {
18
- throw " No downloads folder at ~/Downloads yet"
18
+ throw " No 📂Downloads folder in your home directory yet"
19
19
}
20
20
$path = Resolve-Path " ~/Downloads"
21
21
} else {
Original file line number Diff line number Diff line change 5
5
This PowerShell script changes the working directory to the user's Dropbox folder.
6
6
. EXAMPLE
7
7
PS> ./cd-dropbox
8
- 📂C:\Users\Markus\Dropbox
8
+ 📂C:\Users\Markus\Dropbox (has 2 files and 4 subfolders)
9
9
. LINK
10
10
https://github.com/fleschutz/PowerShell
11
11
. NOTES
12
12
Author: Markus Fleschutz | License: CC0
13
13
#>
14
14
15
15
try {
16
- $path = Resolve-Path " ~/Dropbox"
17
- if (-not (Test-Path " $path " - pathType container)) {
18
- throw " No Dropbox folder at 📂$path - is Dropbox installed?"
16
+ if (-not (Test-Path " ~/Dropbox" - pathType container)) {
17
+ throw " No 📂Dropbox folder in your home directory - is Dropbox installed?"
19
18
}
19
+ $path = Resolve-Path " ~/Dropbox"
20
20
Set-Location " $path "
21
- " 📂$path "
21
+ $files = Get-ChildItem $path - attributes ! Directory
22
+ $folders = Get-ChildItem $path - attributes Directory
23
+ " 📂$path entered (has $ ( $files.Count ) files and $ ( $folders.Count ) subfolders)"
22
24
exit 0 # success
23
25
} catch {
24
26
" ⚠️ Error: $ ( $Error [0 ]) "
Original file line number Diff line number Diff line change 5
5
This PowerShell script changes the working directory to the /etc directory.
6
6
. EXAMPLE
7
7
PS> ./cd-etc
8
- 📂C:\Windows\System32\drivers\etc
8
+ 📂C:\Windows\System32\drivers\etc (has 2 files and 3 subfolders)
9
9
. LINK
10
10
https://github.com/fleschutz/PowerShell
11
11
. NOTES
12
12
Author: Markus Fleschutz | License: CC0
13
13
#>
14
14
15
15
try {
16
- if ($IsLinx ) {
16
+ if ($IsLinux -or $IsMacOS ) {
17
17
$path = " /etc"
18
18
} else {
19
19
$path = Resolve-Path " $env: WINDIR \System32\drivers\etc"
22
22
throw " No /etc directory at 📂$path "
23
23
}
24
24
Set-Location " $path "
25
- " 📂$path "
25
+ $files = Get-ChildItem $path - attributes ! Directory
26
+ $folders = Get-ChildItem $path - attributes Directory
27
+ " 📂$path entered (has $ ( $files.Count ) files and $ ( $folders.Count ) subfolders)"
26
28
exit 0 # success
27
29
} catch {
28
30
" ⚠️ Error: $ ( $Error [0 ]) "
Original file line number Diff line number Diff line change 5
5
This PowerShell script changes the working directory to the fonts folder.
6
6
. EXAMPLE
7
7
PS> ./cd-fonts
8
- 📂C:\Windows\Fonts
8
+ 📂C:\Windows\Fonts (has 2 file and 3 subfolders)
9
9
. LINK
10
10
https://github.com/fleschutz/PowerShell
11
11
. NOTES
18
18
throw " No fonts folder at 📂$path "
19
19
}
20
20
Set-Location " $path "
21
- " 📂$path "
21
+ $files = Get-ChildItem $path - attributes ! Directory
22
+ $folders = Get-ChildItem $path - attributes Directory
23
+ " 📂$path entered (has $ ( $files.Count ) files and $ ( $folders.Count ) subfolders)"
22
24
exit 0 # success
23
25
} catch {
24
26
" ⚠️ Error: $ ( $Error [0 ]) "
Original file line number Diff line number Diff line change 5
5
This PowerShell script changes the working directory to the user's home directory.
6
6
. EXAMPLE
7
7
PS> ./cd-home.ps1
8
- 📂C:\Users\Markus entered (has 4 files and 7 folders )
8
+ 📂C:\Users\Markus entered (has 4 files and 7 subfolders )
9
9
. LINK
10
10
https://github.com/fleschutz/PowerShell
11
11
. NOTES
12
12
Author: Markus Fleschutz | License: CC0
13
13
#>
14
14
15
15
try {
16
+ if (-not (Test-Path " ~" - pathType container)) { throw " No home directory at $path " }
16
17
$path = Resolve-Path " ~"
17
- if (-not (Test-Path " $path " - pathType container)) { throw " No home directory at $path " }
18
18
Set-Location " $path "
19
19
$files = Get-ChildItem $path - attributes ! Directory
20
20
$folders = Get-ChildItem $path - attributes Directory
21
- " 📂$path entered (has $ ( $files.Count ) files and $ ( $folders.Count ) folders )"
21
+ " 📂$path entered (has $ ( $files.Count ) files and $ ( $folders.Count ) subfolders )"
22
22
exit 0 # success
23
23
} catch {
24
24
" ⚠️ Error: $ ( $Error [0 ]) "
Original file line number Diff line number Diff line change 5
5
This PowerShell script changes the current working directory to the logs directory.
6
6
. EXAMPLE
7
7
PS> ./cd-logs
8
- 📂/var/logs
8
+ 📂/var/logs entered (has 3 files and 2 subfolders)
9
9
. LINK
10
10
https://github.com/fleschutz/PowerShell
11
11
. NOTES
12
12
Author: Markus Fleschutz | License: CC0
13
13
#>
14
14
15
15
function GetLogsDir {
16
- if ($IsLinux ) { return " /var/logs" }
16
+ if ($IsLinux -or $IsMacOS ) { return " /var/logs" }
17
17
$WinDir = [System.Environment ]::GetFolderPath(' Windows' )
18
18
return " $WinDir \Logs"
19
19
}
20
20
21
21
try {
22
22
$path = GetLogsDir
23
23
Set-Location " $path "
24
- " 📂$path "
24
+ $files = Get-ChildItem $path - attributes ! Directory
25
+ $folders = Get-ChildItem $path - attributes Directory
26
+ " 📂$path entered (has $ ( $files.Count ) files and $ ( $folders.Count ) subfolders)"
25
27
exit 0 # success
26
28
} catch {
27
29
" ⚠️ Error: $ ( $Error [0 ]) "
You can’t perform that action at this time.
0 commit comments