mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-27 15:12:30 +01:00
Merge branch 'master' of github.com:fleschutz/PowerShell
This commit is contained in:
commit
6eb7f26f1b
@ -2611,7 +2611,8 @@ TPI,Total Profit Improvement
|
|||||||
TPM,Total Productive Maintenance
|
TPM,Total Productive Maintenance
|
||||||
TPM,Trusted Platform Module
|
TPM,Trusted Platform Module
|
||||||
TPOP,Time-Phased Order Point
|
TPOP,Time-Phased Order Point
|
||||||
TPS,terminal proxy server
|
TPS,Terminal Proxy Server
|
||||||
|
TPU,Tensor Processing Unit
|
||||||
TQC,Total Quality Control
|
TQC,Total Quality Control
|
||||||
TQM,Total Quality Management
|
TQM,Total Quality Management
|
||||||
TRI,Toxic Release Inventory
|
TRI,Toxic Release Inventory
|
||||||
|
|
@ -2,21 +2,24 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Lists a directory tree
|
Lists a directory tree
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script lists all files and folders in a directory tree.
|
This PowerShell script lists all files and folders in a neat directory tree (including icon and size).
|
||||||
.PARAMETER DirTree
|
.PARAMETER Path
|
||||||
Specifies the path to the directory tree
|
Specifies the path to the directory tree
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./list-dir-tree.ps1 C:\
|
PS> ./list-dir-tree.ps1 C:\MyFolder
|
||||||
|
├📂Results
|
||||||
|
│ ├📄sales.txt (442K)
|
||||||
|
(2 folders, 1 file, 442K total)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$DirTree = "$PWD")
|
param([string]$Path = "$PWD")
|
||||||
|
|
||||||
function GetFileIcon { param([string]$Suffix)
|
function GetFileIcon([string]$suffix) {
|
||||||
switch ($Suffix) {
|
switch ($suffix) {
|
||||||
".csv" {return "📊"}
|
".csv" {return "📊"}
|
||||||
".epub" {return "📓"}
|
".epub" {return "📓"}
|
||||||
".exe" {return "⚙️"}
|
".exe" {return "⚙️"}
|
||||||
@ -30,32 +33,43 @@ function GetFileIcon { param([string]$Suffix)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ListDir { param([string]$Directory, [int]$Depth)
|
function Bytes2String([int64]$bytes) {
|
||||||
$Depth++
|
if ($bytes -lt 1000) { return "$bytes bytes" }
|
||||||
$Items = Get-ChildItem -path $Directory
|
$bytes /= 1000
|
||||||
foreach($Item in $Items) {
|
if ($bytes -lt 1000) { return "$($bytes)K" }
|
||||||
$Filename = $Item.Name
|
$bytes /= 1000
|
||||||
for ($i = 1; $i -lt $Depth; $i++) { Write-Host "│ " -noNewline }
|
if ($bytes -lt 1000) { return "$($bytes)MB" }
|
||||||
if ($Item.Mode -like "d*") {
|
$bytes /= 1000
|
||||||
Write-Host "├" -noNewline
|
if ($bytes -lt 1000) { return "$($bytes)GB" }
|
||||||
Write-Host -foregroundColor green "📂$Filename"
|
$bytes /= 1000
|
||||||
ListDir "$Directory\$Filename" $Depth
|
return "$($Bytes)TB"
|
||||||
$global:Dirs++
|
}
|
||||||
|
|
||||||
|
function ListDirectory([string]$path, [int]$depth) {
|
||||||
|
$depth++
|
||||||
|
$items = Get-ChildItem -path $path
|
||||||
|
foreach($item in $items) {
|
||||||
|
$filename = $item.Name
|
||||||
|
for ($i = 1; $i -lt $depth; $i++) { Write-Host "│ " -noNewline }
|
||||||
|
if ($item.Mode -like "d*") {
|
||||||
|
Write-Output "├📂$Filename"
|
||||||
|
ListDirectory "$path\$filename" $depth
|
||||||
|
$global:folders++
|
||||||
} else {
|
} else {
|
||||||
$Icon = GetFileIcon $Item.Extension
|
$icon = GetFileIcon $item.Extension
|
||||||
Write-Host "├$($Icon)$Filename ($($Item.Length) bytes)"
|
Write-Output "├$($icon)$filename ($(Bytes2String $item.Length))"
|
||||||
$global:Files++
|
$global:files++
|
||||||
$global:Bytes += $Item.Length
|
$global:bytes += $item.Length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
[int]$global:Dirs = 1
|
[int]$global:folders = 1
|
||||||
[int]$global:Files = 0
|
[int]$global:files = 0
|
||||||
[int]$global:Bytes = 0
|
[int]$global:bytes = 0
|
||||||
ListDir $DirTree 0
|
ListDirectory $Path 0
|
||||||
" ($($global:Dirs) folders, $($global:Files) files, $($global:Bytes) bytes in total)"
|
Write-Output " ($($global:folders) folders, $($global:files) files, $(Bytes2String $global:bytes) total)"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
@ -50,7 +50,7 @@ try {
|
|||||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"✔️ Creating branch '$newBranch' in repo 📂$repoPathName (based on '$currentBranch') took $elapsed sec"
|
"✔️ Created new branch '$newBranch' in repo 📂$repoPathName (based on '$currentBranch', it took $elapsed sec)"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
@ -52,7 +52,7 @@ try {
|
|||||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
"✔️ Switching repo 📂$RepoDirName to branch '$BranchName' took $Elapsed sec"
|
"✔️ Switched repo 📂$RepoDirName to branch '$BranchName' (in $Elapsed sec)"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
@ -26,9 +26,9 @@ function GetRandomCodeLine {
|
|||||||
0 { return $Tabs + "`$count = 0" }
|
0 { return $Tabs + "`$count = 0" }
|
||||||
1 { return $Tabs + "`$count++" }
|
1 { return $Tabs + "`$count++" }
|
||||||
2 { return $Tabs + "exit 0 # success" }
|
2 { return $Tabs + "exit 0 # success" }
|
||||||
3 { return $Tabs + "`$Files = Get-ChildItem C:" }
|
3 { return $Tabs + "`$files = Get-ChildItem C:" }
|
||||||
4 { return $Tabs + "Start-Sleep -seconds 1" }
|
4 { return $Tabs + "Start-Sleep -seconds 1" }
|
||||||
5 { return $Tabs + "`$Generator = New-Object System-Random" }
|
5 { return $Tabs + "`$generator = New-Object System-Random" }
|
||||||
6 { $global:Tabs = " "; return "} else {" }
|
6 { $global:Tabs = " "; return "} else {" }
|
||||||
7 { $global:Tabs = " "; return "} catch {" }
|
7 { $global:Tabs = " "; return "} catch {" }
|
||||||
8 { $global:Tabs = " "; return "} elseif (`$count -eq 0) {" }
|
8 { $global:Tabs = " "; return "} elseif (`$count -eq 0) {" }
|
||||||
@ -39,21 +39,21 @@ function GetRandomCodeLine {
|
|||||||
13 { return $Tabs + "return 1" }
|
13 { return $Tabs + "return 1" }
|
||||||
14 { return $Tabs + "return 0" }
|
14 { return $Tabs + "return 0" }
|
||||||
15 { return $Tabs + "Write-Progress `"Working...`" " }
|
15 { return $Tabs + "Write-Progress `"Working...`" " }
|
||||||
16 { return $Tabs + "[bool]`$KeepAlive = `$true" }
|
16 { return $Tabs + "[bool]`$keepAlive = `$true" }
|
||||||
17 { return $Tabs + "# Copyright © 2023 write-code.ps1. All Rights Reserved." }
|
17 { return $Tabs + "# Copyright © 2023 write-code.ps1. All Rights Reserved." }
|
||||||
18 { $global:Tabs = " "; return "for ([int]`$i = 0; `$i -lt 42; `$i++) {" }
|
18 { $global:Tabs = " "; return "for ([int]`$i = 0; `$i -lt 42; `$i++) {" }
|
||||||
19 { return $Tabs + "`$StopWatch = [system.diagnostics.stopwatch]::startNew()" }
|
19 { return $Tabs + "`$stopWatch = [system.diagnostics.stopwatch]::startNew()" }
|
||||||
20 { return $Tabs + "[int]`$Elapsed = `$StopWatch.Elapsed.TotalSeconds" }
|
20 { return $Tabs + "[int]`$elapsed = `$stopWatch.Elapsed.TotalSeconds" }
|
||||||
21 { $global:Tabs = " "; return "if (`$count -eq 42) {" }
|
21 { $global:Tabs = " "; return "if (`$count -eq 42) {" }
|
||||||
22 { $global:Tabs = " "; return "} finally {" }
|
22 { $global:Tabs = " "; return "} finally {" }
|
||||||
23 { return $Tabs + "throw `"Can't open file`" " }
|
23 { return $Tabs + "throw `"Can't open file`" " }
|
||||||
24 { return $Tabs + "Start-Sleep -milliseconds 42" }
|
24 { return $Tabs + "Start-Sleep -milliseconds 42" }
|
||||||
25 { return $Tabs + "`$Choice = Read-Host `"Red or blue pill?`"" }
|
25 { return $Tabs + "`$Choice = Read-Host `"Red or blue pill?`"" }
|
||||||
26 { return $Tabs + "[int]`$Answer = 42" }
|
26 { return $Tabs + "[int]`$answer = 42" }
|
||||||
27 { $global:Tabs = ""; return "}" }
|
27 { $global:Tabs = ""; return "}" }
|
||||||
28 { $global:Tabs = " "; return "try {" }
|
28 { $global:Tabs = " "; return "try {" }
|
||||||
29 { $global:Tabs = " "; return "foreach(`$Row in `$Table) {" }
|
29 { $global:Tabs = " "; return "foreach(`$row in `$table) {" }
|
||||||
30 { $global:Tabs = " "; return "foreach(`$File in `$Files) {" }
|
30 { $global:Tabs = " "; return "foreach(`$file in `$files) {" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user