Skip to content

Commit 21dcdef

Browse files
authored
Merge pull request #39 from santisq/38-improve-how-include-works
Improves how `-Include` works
2 parents 6c617ee + 3567b8b commit 21dcdef

24 files changed

+602
-532
lines changed

CHANGELOG.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,79 @@
11
# CHANGELOG
22

3+
- __01/19/2025__
4+
- Big code refactoring, this update improves readability and simplicity.
5+
- Updates to `-Include` and `-Exclude` parameters, with this update the patterns are evaluated using the
6+
object's `.Name` property instead of `.FullName`.
7+
- In addition to the above, this update improves how the cmdlet displays trees when `-Include` is used.
8+
Before, the cmdlet would display trees where no file was matched by the include patterns. Now, only trees having files matched by the include patterns are displayed.
9+
10+
```powershell
11+
# PSTree v2.2.0
12+
PS ..\pwsh> Get-PSTree ..\PSTree -Include *.ps1, *.cs -Exclude *tools, *output
13+
14+
Source: C:\User\PSTree
15+
16+
Mode Length Hierarchy
17+
---- ------ ---------
18+
d---- 29.57 KB PSTree
19+
-a--- 1.34 KB ├── build.ps1
20+
d---- 0.00 B ├── .github
21+
d---- 4.10 KB │ └── workflows
22+
d---- 4.11 KB ├── .vscode
23+
d---- 229.32 KB ├── assets
24+
d---- 0.00 B ├── docs
25+
d---- 12.55 KB │ └── en-US
26+
d---- 13.63 KB ├── module
27+
d---- 0.00 B ├── src
28+
d---- 11.50 KB │ └── PSTree
29+
-a--- 1.06 KB │ ├── Cache.cs
30+
-a--- 2.65 KB │ ├── CommandWithPathBase.cs
31+
-a--- 2.98 KB │ ├── PSTreeDirectory.cs
32+
-a--- 1.42 KB │ ├── PSTreeFile.cs
33+
-a--- 1.69 KB │ ├── PSTreeFileSystemInfo_T.cs
34+
-a--- 524.00 B │ ├── PSTreeFileSystemInfo.cs
35+
-a--- 404.00 B │ ├── TreeComparer.cs
36+
d---- 0.00 B │ ├── bin
37+
d---- 6.54 KB │ ├── Commands
38+
d---- 3.63 KB │ ├── Extensions
39+
d---- 1.14 KB │ ├── Internal
40+
d---- 16.83 KB │ ├── obj
41+
d---- 9.28 KB │ └── Style
42+
d---- 17.87 KB └── tests
43+
-a--- 765.00 B ├── FormattingInternals.tests.ps1
44+
-a--- 6.15 KB ├── GetPSTreeCommand.tests.ps1
45+
-a--- 1.77 KB ├── PSTreeDirectory.tests.ps1
46+
-a--- 920.00 B ├── PSTreeFile.tests.ps1
47+
-a--- 2.63 KB ├── PSTreeFileSystemInfo_T.tests.ps1
48+
-a--- 4.90 KB └── TreeStyle.tests.ps1
49+
50+
# PSTree v2.2.1
51+
PS ..\pwsh> Get-PSTree ..\PSTree -Include *.ps1, *.cs -Exclude tools, output
52+
53+
Source: C:\User\PSTree
54+
55+
Mode Length Hierarchy
56+
---- ------ ---------
57+
d---- 1.34 KB PSTree
58+
-a--- 1.34 KB ├── build.ps1
59+
d---- 0.00 B ├── src
60+
d---- 10.70 KB │ └── PSTree
61+
-a--- 1.06 KB │ ├── Cache.cs
62+
-a--- 2.65 KB │ ├── CommandWithPathBase.cs
63+
-a--- 2.98 KB │ ├── PSTreeDirectory.cs
64+
-a--- 1.42 KB │ ├── PSTreeFile.cs
65+
-a--- 1.69 KB │ ├── PSTreeFileSystemInfo_T.cs
66+
-a--- 524.00 B │ ├── PSTreeFileSystemInfo.cs
67+
-a--- 404.00 B │ └── TreeComparer.cs
68+
d---- 17.10 KB └── tests
69+
-a--- 765.00 B ├── FormattingInternals.tests.ps1
70+
-a--- 6.15 KB ├── GetPSTreeCommand.tests.ps1
71+
-a--- 1.77 KB ├── PSTreeDirectory.tests.ps1
72+
-a--- 920.00 B ├── PSTreeFile.tests.ps1
73+
-a--- 2.63 KB ├── PSTreeFileSystemInfo_T.tests.ps1
74+
-a--- 4.90 KB └── TreeStyle.tests.ps1
75+
```
76+
377
- __09/12/2024__
478
- Added `TreeStyle` type and `Get-PSTreeStyle` cmdlet for rendering output.
579
- Added Pester tests for `TreeStyle`.
@@ -8,7 +82,7 @@
882
- __09/03/2024__
983
- Makes `Depth` property public for `PSTreeFileSystemInfo` instances.
1084
- Makes `GetParents()` method private, absolutely no reason to have it public.
11-
- Added properties `ItemCount` and `TotalItemCount` to `PSTreeDirectory` instances, requested in [__Issue #34__][2].
85+
- Added properties `ItemCount` and `TotalItemCount` to `PSTreeDirectory` instances, requested in [__Issue #34__][21].
1286
1387
```powershell
1488
PS ..\PSTree> pstree -Recurse -Force -Directory | Select-Object Hierarchy, Depth, ItemCount, TotalItemCount -First 15
@@ -275,4 +349,4 @@ d---- └── Format 1.83 Kb
275349
[18]: https://github.com/jborean93/
276350
[19]: /docs/en-US/Get-PSTree.md
277351
[20]: https://www.powershellgallery.com/
278-
[2]: https://github.com/santisq/PSTree/issues/34
352+
[21]: https://github.com/santisq/PSTree/issues/34

README.md

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Compatible with __Windows PowerShell v5.1__ and [__PowerShell 7+__](https://gith
4848
```powershell
4949
PS ..\PSTree> Get-PSTree | Select-Object -First 20
5050
51-
Source: C:\path\to\PSTree
51+
Source: C:\User\Documents\PSTree
5252
5353
Mode Length Hierarchy
5454
---- ------ ---------
@@ -77,101 +77,93 @@ d---- 0.00 B ├── src
7777
### Exclude `tools` and `tests` folders
7878

7979
```powershell
80-
PS ..\PSTree> Get-PSTree -Exclude *tools, *tests | Select-Object -First 20
80+
PS ..\PSTree> Get-PSTree -Exclude tools, tests | Select-Object -First 20
8181
82-
Source: C:\path\to\PSTree
82+
Source: C:\User\Documents\PSTree
8383
8484
Mode Length Hierarchy
8585
---- ------ ---------
86-
d---- 31.20 KB PSTree
87-
-a--- 4.64 KB ├── .gitignore
86+
d---- 33.23 KB PSTree
87+
-a--- 4.75 KB ├── .gitignore
8888
-a--- 137.00 B ├── .markdownlint.json
89-
-a--- 2.16 KB ├── build.ps1
90-
-a--- 7.90 KB ├── CHANGELOG.md
89+
-a--- 1.34 KB ├── build.ps1
90+
-a--- 18.08 KB ├── CHANGELOG.md
9191
-a--- 1.07 KB ├── LICENSE
92-
-a--- 8.10 KB ├── PSTree.build.ps1
93-
-a--- 5.96 KB ├── README.md
94-
-a--- 1.23 KB ── ScriptAnalyzerSettings.psd1
95-
d---- 0.00 B ├── src
96-
d---- 10.30 KB │ └── PSTree
97-
-a--- 931.00 B │ ├── ExceptionHelpers.cs
98-
-a--- 439.00 B ├── PSTree.csproj
99-
-a--- 1.06 KB │ ├── PSTreeDirectory.cs
100-
-a--- 4.01 KB │ ── PSTreeExtensions.cs
101-
-a--- 517.00 B │ ├── PSTreeFile.cs
102-
-a--- 399.00 B ├── PSTreeFileSystemInfo.cs
103-
-a--- 1.51 KB │ ├── PSTreeFileSystemInfo_T.cs
104-
-a--- 897.00 B ├── PSTreeHelper.cs
105-
-a--- 619.00 B ── PSTreeIndexer.cs
92+
-a--- 7.85 KB ├── README.md
93+
d---- 0.00 B ├── .github
94+
d---- 4.10 KB │ └── workflows
95+
-a--- 4.10 KB │ └── ci.yml
96+
d---- 4.11 KB ── .vscode
97+
-a--- 275.00 B │ ├── extensions.json
98+
-a--- 1.39 KB │ ├── launch.json
99+
-a--- 1.02 KB │ ├── settings.json
100+
-a--- 1.43 KB │ ── tasks.json
101+
d---- 229.32 KB ├── assets
102+
-a--- 10.00 KB │ ├── EscapeSequence.png
103+
-a--- 78.08 KB │ ├── Example.After.png
104+
-a--- 73.89 KB │ ├── Example.Before.png
105+
-a--- 67.35 KB ── TreeStyle.png
106106
```
107107

108-
### Include `.ps1` and `.cs` files and exclude some folders
108+
### Include `.ps1` and `.cs` files and exclude `tools` folder
109109

110110
```powershell
111-
PS ..\PSTree> Get-PStree -Include *.ps1, *.cs -Exclude *output, *tools, *docs, *module
111+
PS ..\PSTree> Get-PStree -Include *.ps1, *.cs -Exclude tools
112112
113-
Source: C:\path\to\PSTree
113+
Source: C:\User\Documents\PSTree
114114
115115
Mode Length Hierarchy
116116
---- ------ ---------
117-
d---- 33.15 KB PSTree
118-
-a--- 2.35 KB ├── build.ps1
119-
-a--- 8.10 KB ├── PSTree.build.ps1
120-
d---- 13.29 KB ├── tests
121-
-a--- 765.00 B │ ├── FormattingInternals.tests.ps1
122-
-a--- 5.89 KB │ ├── GetPSTreeCommand.tests.ps1
123-
-a--- 1.51 KB │ ├── PathExtensions.tests.ps1
124-
-a--- 1.38 KB │ ├── PSTreeDirectory.ps1
125-
-a--- 920.00 B │ ├── PSTreeFile.tests.ps1
126-
-a--- 2.09 KB │ └── PSTreeFileSystemInfo_T.tests.ps1
117+
d---- 1.34 KB PSTree
118+
-a--- 1.34 KB ├── build.ps1
127119
d---- 0.00 B ├── src
128-
d---- 12.15 KB │ └── PSTree
129-
-a--- 931.00 B │ ├── ExceptionHelpers.cs
130-
-a--- 4.09 KB │ ├── PathExtensions.cs
131-
-a--- 900.00 B │ ├── PSTreeCache.cs
132-
-a--- 1.06 KB │ ├── PSTreeDirectory.cs
133-
-a--- 1.66 KB │ ├── PSTreeExtensions.cs
134-
-a--- 517.00 B │ ├── PSTreeFile.cs
135-
-a--- 399.00 B │ ├── PSTreeFileSystemInfo.cs
136-
-a--- 1.61 KB │ ├── PSTreeFileSystemInfo_T.cs
137-
-a--- 626.00 B │ ├── PSTreeIndexer.cs
138-
d---- 16.53 KB │ ├── obj
139-
d---- 1.15 KB │ ├── Internal
140-
d---- 6.43 KB │ ├── Commands
141-
d---- 0.00 B │ └── bin
142-
d---- 4.07 KB ├── .vscode
143-
d---- 0.00 B └── .github
144-
d---- 4.17 KB └── workflows
120+
d---- 10.70 KB │ └── PSTree
121+
-a--- 1.06 KB │ ├── Cache.cs
122+
-a--- 2.65 KB │ ├── CommandWithPathBase.cs
123+
-a--- 2.98 KB │ ├── PSTreeDirectory.cs
124+
-a--- 1.42 KB │ ├── PSTreeFile.cs
125+
-a--- 1.69 KB │ ├── PSTreeFileSystemInfo_T.cs
126+
-a--- 524.00 B │ ├── PSTreeFileSystemInfo.cs
127+
-a--- 404.00 B │ └── TreeComparer.cs
128+
d---- 17.10 KB └── tests
129+
-a--- 765.00 B ├── FormattingInternals.tests.ps1
130+
-a--- 6.15 KB ├── GetPSTreeCommand.tests.ps1
131+
-a--- 1.77 KB ├── PSTreeDirectory.tests.ps1
132+
-a--- 920.00 B ├── PSTreeFile.tests.ps1
133+
-a--- 2.63 KB ├── PSTreeFileSystemInfo_T.tests.ps1
134+
-a--- 4.90 KB └── TreeStyle.tests.ps1
145135
```
146136

147137
### Get the `src` tree recursively displaying only folders
148138

149139
```powershell
150140
PS ..\PSTree> Get-PSTree .\src\ -Recurse -Directory
151141
152-
Source: C:\path\to\PSTree\src
142+
Source: C:\User\Documents\PSTree\src
153143
154144
Mode Length Hierarchy
155145
---- ------ ---------
156146
d---- 0.00 B src
157-
d---- 10.30 KB └── PSTree
158-
d---- 16.53 KB ├── obj
147+
d---- 11.50 KB └── PSTree
148+
d---- 0.00 B ├── bin
159149
d---- 0.00 B │ └── Debug
160-
d---- 88.02 KB │ └── netstandard2.0
161-
d---- 1.13 KB ├── Internal
162-
d---- 5.68 KB ├── Commands
163-
d---- 0.00 B └── bin
164-
d---- 0.00 B └── Debug
165-
d---- 33.31 KB └── netstandard2.0
166-
d---- 33.11 KB └── publish
150+
d---- 56.49 KB │ └── netstandard2.0
151+
d---- 56.29 KB │ └── publish
152+
d---- 6.54 KB ├── Commands
153+
d---- 3.63 KB ├── Extensions
154+
d---- 1.14 KB ├── Internal
155+
d---- 16.83 KB ├── obj
156+
d---- 0.00 B │ └── Debug
157+
d---- 112.44 KB │ └── netstandard2.0
158+
d---- 9.28 KB └── Style
167159
```
168160

169161
### Display subdirectories only 2 levels deep
170162

171163
```powershell
172164
PS ..\PSTree> Get-PSTree .\src\ -Depth 2 -Directory
173165
174-
Source: C:\path\to\PSTree\src
166+
Source: C:\User\Documents\PSTree\src
175167
176168
Mode Length Hierarchy
177169
---- ------ ---------
@@ -188,7 +180,7 @@ d---- 0.00 B └── bin
188180
```powershell
189181
PS ..\PSTree> Get-PSTree .\src\ -Depth 2 -Directory -RecursiveSize
190182
191-
Source: C:\path\to\PSTree\src
183+
Source: C:\User\Documents\PSTree\src
192184
193185
Mode Length Hierarchy
194186
---- ------ ---------
@@ -207,4 +199,4 @@ d---- 66.42 KB └── bin
207199

208200
## Contributing
209201

210-
Contributions are more than welcome, if you wish to contribute, fork this repository and submit a pull request with the changes.
202+
Contributions are welcome, if you wish to contribute, fork this repository and submit a pull request with the changes.

docs/en-US/Get-PSTree.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ schema: 2.0.0
1818
```powershell
1919
Get-PSTree
2020
[[-Path] <String[]>]
21-
[-Depth <UInt32>]
21+
[-Depth <Int32>]
2222
[-Recurse]
2323
[-Force]
2424
[-Directory]
@@ -33,7 +33,7 @@ Get-PSTree
3333
```powershell
3434
Get-PSTree
3535
[-LiteralPath <String[]>]
36-
[-Depth <UInt32>]
36+
[-Depth <Int32>]
3737
[-Recurse]
3838
[-Force]
3939
[-Directory]
@@ -71,7 +71,8 @@ In this example `$HOME` is bound positionally to the `-Path` parameter.
7171
PS ..\PSTree> Get-PSTree -Depth 2 -Force
7272
```
7373

74-
The `-Force` switch is needed to display hidden files and folders. In addition, hidden child items do not add up to the folders size without this switch.
74+
> [!TIP]
75+
> The `-Force` switch is needed to display hidden files and folders. In addition, hidden child items do not add up to the folders size without this switch.
7576
7677
### Example 4: Get the `C:\` drive tree 2 levels in depth displaying only folders calculating the recursive size
7778

@@ -85,23 +86,28 @@ PS ..\PSTree> Get-PSTree C:\ -Depth 2 -RecursiveSize -Directory
8586
PS ..\PSTree> Get-PSTree $HOME -Recurse -Exclude *.jpg, *.png
8687
```
8788

88-
The `-Exclude` parameter supports [wildcard patterns](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.3), exclusion patterns are tested against the items `.FullName` property. Excluded items do not do not add to the folders size.
89+
> [!NOTE]
90+
>
91+
> - The `-Exclude` parameter supports [wildcard patterns](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.3), exclusion patterns are evaluated using the items `.Name` property.
92+
> - __Excluded items do not do not add to the folders size.__
8993
9094
### Example 6: Get the tree of all folders in a location
9195

9296
```powershell
9397
PS ..\PSTree> Get-ChildItem -Directory | Get-PSTree
9498
```
9599

96-
`DirectoryInfo` and `FileInfo` instances having the `PSPath` Property are bound to the `-LiteralPath` parameter.
100+
> [!TIP]
101+
> Output from `Get-ChildItem` can be piped to this cmdlet. Pipeline input is bound to `-LiteralPath` parameter if the items have a `PSPath` property.
97102
98103
### Example 7: Get the tree of all folders in a location including only `*.ps1` files
99104

100105
```powershell
101106
PS ..\PSTree> Get-ChildItem -Directory | Get-PSTree -Include *.ps1
102107
```
103108

104-
Similar to `-Exclude`, the `-Include` parameter supports [wildcard patterns](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.3), however, __this parameter works only with Files__.
109+
> [!IMPORTANT]
110+
> Similar to `-Exclude`, the `-Include` parameter supports [wildcard patterns](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.3), however, __this parameter works only with Files__.
105111
106112
## PARAMETERS
107113

@@ -110,7 +116,7 @@ Similar to `-Exclude`, the `-Include` parameter supports [wildcard patterns](htt
110116
Determines the number of subdirectory levels that are included in the recursion.
111117

112118
```yaml
113-
Type: UInt32
119+
Type: Int32
114120
Parameter Sets: (All)
115121
Aliases:
116122

@@ -147,8 +153,8 @@ Excluded items do not add to the recursive folders size.
147153
148154
> [!NOTE]
149155
>
150-
> - Patterns are tested against the object's `.FullName` property.
151-
> - The `-Include` and `-Exclude` parameters can be used together and the inclusions are applied after the exclusions.
156+
> - Patterns are evaluated using the object's `.Name` property.
157+
> - The `-Include` and `-Exclude` parameters can be used together, however the exclusions are applied before the inclusions.
152158

153159
```yaml
154160
Type: String[]
@@ -186,9 +192,9 @@ Wildcard characters are accepted.
186192

187193
> [!NOTE]
188194
>
189-
> - Patterns are tested against the object's `.FullName` property.
190-
> - This parameter focuses only on files, the inclusion patterns are only evaluated against `FileInfo` instances.
191-
> - The `-Include` and `-Exclude` parameters can be used together and the inclusions are applied after the exclusions.
195+
> - __This parameter works only on files.__
196+
> - Patterns are evaluated using the object's `.Name` property.
197+
> - The `-Include` and `-Exclude` parameters can be used together, however the exclusions are applied before the inclusions.
192198

193199
```yaml
194200
Type: String[]
@@ -222,7 +228,8 @@ Accept wildcard characters: False
222228

223229
### -Path
224230

225-
Specifies a path to one or more locations. Wildcards are accepted. The default location is the current directory (`.`).
231+
Specifies a path to one or more locations. Wildcards are accepted.
232+
The default location is the current directory (`$PWD`).
226233

227234
```yaml
228235
Type: String[]
@@ -231,7 +238,7 @@ Aliases:
231238
232239
Required: False
233240
Position: 0
234-
Default value: Current directory
241+
Default value: $PWD
235242
Accept pipeline input: True (ByValue)
236243
Accept wildcard characters: True
237244
```

module/PSTree.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'bin/netstandard2.0/PSTree.dll'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2.2.0'
14+
ModuleVersion = '2.2.1'
1515

1616
# Supported PSEditions
1717
# CompatiblePSEditions = @()

0 commit comments

Comments
 (0)