Skip to content

Commit bde14e8

Browse files
v2.17.0
1 parent cb4e02e commit bde14e8

File tree

8 files changed

+398
-22
lines changed

8 files changed

+398
-22
lines changed

PSScriptTools.psd1

58 Bytes
Binary file not shown.

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,27 @@ Results will vary depending on whether you are running PowerShell on Windows nor
294294

295295
## File Tools
296296

297+
### [Test-EmptyFolder](docs/Test-EmptyFolder.md)
298+
299+
This command will test if a given folder path is empty of all files anywhere in the path.
300+
This includes hidden files.
301+
The command will return True even if there are empty sub-folders.
302+
The default output is True or False but you can use -Passthru to get more information.
303+
304+
```powershell
305+
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
306+
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
307+
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
308+
What if: Performing the operation "Remove Directory" on target "C:\work\new".
309+
What if: Performing the operation "Remove Directory" on target "C:\work\sqlback".
310+
What if: Performing the operation "Remove Directory" on target "C:\work\todd".
311+
What if: Performing the operation "Remove Directory" on target "C:\work\[data]".
312+
```
313+
314+
Find all empty sub-folders under C:\Work and pipe them to Remove-Item.
315+
This is one way to remove empty folders.
316+
The example is piping objects to ForEach-Object so that Remove-Item can use the -LiteralPath parameter, because C:\work\[data] is a non-standard path.
317+
297318
### [Get-FolderSizeInfo](docs/Get-FolderSizeInfo.md)
298319

299320
Use this command to quickly get the size of a folder. You also have an option to include hidden files. The command will measure all files in all subdirectories. The command includes a format file with additional view to display the total size in MB or GB.
@@ -1145,6 +1166,6 @@ You will need to manually install the file.
11451166

11461167
## Compatibility
11471168

1148-
Where possible these commands have been tested with PowerShell 7, but not every platform. If you encounter problems, have suggestions or other feedback, please post an issue. It is assumed you will not be running this commands on any edition of PowerShell Core or any beta releases of PowerShell 7.
1169+
Where possible these commands have been tested with PowerShell 7, but not every platform. If you encounter problems, have suggestions or other feedback, please post an issue. It is assumed you will __not__ be running this commands on any edition of PowerShell Core or any beta releases of PowerShell 7.
11491170

1150-
Last Updated *2020-02-12 19:38:27Z UTC*
1171+
Last Updated *2020-02-26 15:10:48Z UTC*

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log for PSScriptTools
22

3+
## v2.17.0
4+
5+
+ Updated `Get-FolderSizeInfo` to handle directory names like `[data]` (Issue #65)
6+
+ Updated `Get-FolderSizeInfo` to show a TotalSize of 0 for empty directories (Issue #64)
7+
+ Cleaned up code in `Get-FolderSizeInfo` script file now that it is part of this module.
8+
+ Added `Test-EmptyFolder`
9+
+ Updated `README.md`
10+
311
## v2.16.0
412

513
+ Fixed bug in `New-CustomFileName` when using a 24 hour value. (Issue #62)

docs/Get-FolderSizeInfo.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Get-FolderSizeInfo [-Path] <String[]> [-Hidden] [<CommonParameters>]
1919

2020
## DESCRIPTION
2121

22-
This command is an alternative to discovering the size of a folder, or at least an easier method. Use the -Hidden parameter to include hidden files in the output. The measurement will include all files in all subfolders.
22+
This command is an alternative to discovering the size of a folder, or at least an easier method. Use the -Hidden parameter to include hidden files in the output. The measurement will include all files in all sub-folders.
2323

2424
## EXAMPLES
2525

@@ -73,7 +73,7 @@ Get the top level directories from D and pipe them to Get-FolderSizeInfo. Items
7373

7474
### -Hidden
7575

76-
Include hidden directories
76+
Include hidden directories.
7777

7878
```yaml
7979
Type: SwitchParameter
@@ -122,6 +122,8 @@ http://jdhitsolutions.com/blog/essential-powershell-resources/
122122
123123
## RELATED LINKS
124124
125+
[Test-EmptyFolder]()
126+
125127
[Get-Childitem]()
126128
127129
[Measure-Object]()

docs/Test-EmptyFolder.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
external help file: PSScriptTools-help.xml
3+
Module Name: PSScriptTools
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Test-EmptyFolder
9+
10+
## SYNOPSIS
11+
12+
Test if a folder is empty of files
13+
14+
## SYNTAX
15+
16+
```yaml
17+
Test-EmptyFolder [-Path] <String[]> [-Passthru] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
This command will test if a given folder path is empty of all files anywhere in the path.
23+
This includes hidden files.
24+
The command will return True even if there are empty sub-folders.
25+
The default output is True or False but you can use -Passthru to get more information.
26+
See examples.
27+
28+
## EXAMPLES
29+
30+
### Example 1
31+
32+
```powershell
33+
PS C:\> Test-EmptyFolder c:\work
34+
False
35+
```
36+
37+
Test a single folder from a parameter.
38+
39+
### Example 2
40+
41+
```powershell
42+
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru
43+
44+
Path Name IsEmpty
45+
---- ---- -------
46+
C:\work\A A False
47+
C:\work\alpha alpha False
48+
C:\work\B B False
49+
C:\work\data data False
50+
C:\work\demo3 demo3 True
51+
...
52+
```
53+
54+
Test child folders under C:\work.
55+
56+
### Example 3
57+
58+
```powershell
59+
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
60+
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
61+
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
62+
What if: Performing the operation "Remove Directory" on target "C:\work\new".
63+
What if: Performing the operation "Remove Directory" on target "C:\work\sqlback".
64+
What if: Performing the operation "Remove Directory" on target "C:\work\todd".
65+
What if: Performing the operation "Remove Directory" on target "C:\work\[data]".
66+
```
67+
68+
Find all empty sub-folders under C:\Work and pipe them to Remove-Item.
69+
This is one way to remove empty folders.
70+
The example is piping objects to ForEach-Object so that Remove-Item can use the -LiteralPath parameter, because C:\work\[data] is a non-standard path.
71+
72+
## PARAMETERS
73+
74+
### -Passthru
75+
76+
Write a test object to the pipeline
77+
78+
```yaml
79+
Type: SwitchParameter
80+
Parameter Sets: (All)
81+
Aliases:
82+
83+
Required: False
84+
Position: Named
85+
Default value: None
86+
Accept pipeline input: False
87+
Accept wildcard characters: False
88+
```
89+
90+
### -Path
91+
92+
Enter a file system path like C:\Scripts.
93+
94+
```yaml
95+
Type: String[]
96+
Parameter Sets: (All)
97+
Aliases: PSPath
98+
99+
Required: True
100+
Position: 0
101+
Default value: None
102+
Accept pipeline input: True (ByPropertyName, ByValue)
103+
Accept wildcard characters: False
104+
```
105+
106+
### CommonParameters
107+
108+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
109+
110+
## INPUTS
111+
112+
### System.String[]
113+
114+
## OUTPUTS
115+
116+
### Boolean
117+
118+
### EmptyFolder
119+
120+
## NOTES
121+
122+
Learn more about PowerShell:
123+
http://jdhitsolutions.com/blog/essential-powershell-resources/
124+
125+
## RELATED LINKS
126+
127+
[Get-FolderSizeInfo]
128+
()

en-us/PSScriptTools-help.xml

Lines changed: 152 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,7 +4147,7 @@ Mode LastWriteTime Length Name
41474147
</maml:description>
41484148
</command:details>
41494149
<maml:description>
4150-
<maml:para>This command is an alternative to discovering the size of a folder, or at least an easier method. Use the -Hidden parameter to include hidden files in the output. The measurement will include all files in all subfolders.</maml:para>
4150+
<maml:para>This command is an alternative to discovering the size of a folder, or at least an easier method. Use the -Hidden parameter to include hidden files in the output. The measurement will include all files in all sub-folders.</maml:para>
41514151
</maml:description>
41524152
<command:syntax>
41534153
<command:syntaxItem>
@@ -4167,7 +4167,7 @@ Mode LastWriteTime Length Name
41674167
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
41684168
<maml:name>Hidden</maml:name>
41694169
<maml:Description>
4170-
<maml:para>Include hidden directories</maml:para>
4170+
<maml:para>Include hidden directories.</maml:para>
41714171
</maml:Description>
41724172
<dev:type>
41734173
<maml:name>SwitchParameter</maml:name>
@@ -4181,7 +4181,7 @@ Mode LastWriteTime Length Name
41814181
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
41824182
<maml:name>Hidden</maml:name>
41834183
<maml:Description>
4184-
<maml:para>Include hidden directories</maml:para>
4184+
<maml:para>Include hidden directories.</maml:para>
41854185
</maml:Description>
41864186
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
41874187
<dev:type>
@@ -4279,6 +4279,10 @@ BOVINE320 D:\2016 5
42794279
<maml:linkText>Online Version:</maml:linkText>
42804280
<maml:uri>http://bit.ly/2RCoWQ6</maml:uri>
42814281
</maml:navigationLink>
4282+
<maml:navigationLink>
4283+
<maml:linkText>Test-EmptyFolder</maml:linkText>
4284+
<maml:uri></maml:uri>
4285+
</maml:navigationLink>
42824286
<maml:navigationLink>
42834287
<maml:linkText>Get-Childitem</maml:linkText>
42844288
<maml:uri></maml:uri>
@@ -10836,6 +10840,151 @@ WSMan:\
1083610840
</maml:navigationLink>
1083710841
</command:relatedLinks>
1083810842
</command:command>
10843+
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
10844+
<command:details>
10845+
<command:name>Test-EmptyFolder</command:name>
10846+
<command:verb>Test</command:verb>
10847+
<command:noun>EmptyFolder</command:noun>
10848+
<maml:description>
10849+
<maml:para>Test if a folder is empty of files</maml:para>
10850+
</maml:description>
10851+
</command:details>
10852+
<maml:description>
10853+
<maml:para>This command will test if a given folder path is empty of all files anywhere in the path. This includes hidden files. The command will return True even if there are empty sub-folders. The default output is True or False but you can use -Passthru to get more information. See examples.</maml:para>
10854+
</maml:description>
10855+
<command:syntax>
10856+
<command:syntaxItem>
10857+
<maml:name>Test-EmptyFolder</maml:name>
10858+
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="0" aliases="PSPath">
10859+
<maml:name>Path</maml:name>
10860+
<maml:Description>
10861+
<maml:para>Enter a file system path like C:\Scripts.</maml:para>
10862+
</maml:Description>
10863+
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
10864+
<dev:type>
10865+
<maml:name>String[]</maml:name>
10866+
<maml:uri />
10867+
</dev:type>
10868+
<dev:defaultValue>None</dev:defaultValue>
10869+
</command:parameter>
10870+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
10871+
<maml:name>Passthru</maml:name>
10872+
<maml:Description>
10873+
<maml:para>Write a test object to the pipeline</maml:para>
10874+
</maml:Description>
10875+
<dev:type>
10876+
<maml:name>SwitchParameter</maml:name>
10877+
<maml:uri />
10878+
</dev:type>
10879+
<dev:defaultValue>False</dev:defaultValue>
10880+
</command:parameter>
10881+
</command:syntaxItem>
10882+
</command:syntax>
10883+
<command:parameters>
10884+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
10885+
<maml:name>Passthru</maml:name>
10886+
<maml:Description>
10887+
<maml:para>Write a test object to the pipeline</maml:para>
10888+
</maml:Description>
10889+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
10890+
<dev:type>
10891+
<maml:name>SwitchParameter</maml:name>
10892+
<maml:uri />
10893+
</dev:type>
10894+
<dev:defaultValue>False</dev:defaultValue>
10895+
</command:parameter>
10896+
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="0" aliases="PSPath">
10897+
<maml:name>Path</maml:name>
10898+
<maml:Description>
10899+
<maml:para>Enter a file system path like C:\Scripts.</maml:para>
10900+
</maml:Description>
10901+
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
10902+
<dev:type>
10903+
<maml:name>String[]</maml:name>
10904+
<maml:uri />
10905+
</dev:type>
10906+
<dev:defaultValue>None</dev:defaultValue>
10907+
</command:parameter>
10908+
</command:parameters>
10909+
<command:inputTypes>
10910+
<command:inputType>
10911+
<dev:type>
10912+
<maml:name>System.String[]</maml:name>
10913+
</dev:type>
10914+
<maml:description>
10915+
<maml:para></maml:para>
10916+
</maml:description>
10917+
</command:inputType>
10918+
</command:inputTypes>
10919+
<command:returnValues>
10920+
<command:returnValue>
10921+
<dev:type>
10922+
<maml:name>Boolean</maml:name>
10923+
</dev:type>
10924+
<maml:description>
10925+
<maml:para></maml:para>
10926+
</maml:description>
10927+
</command:returnValue>
10928+
<command:returnValue>
10929+
<dev:type>
10930+
<maml:name>EmptyFolder</maml:name>
10931+
</dev:type>
10932+
<maml:description>
10933+
<maml:para></maml:para>
10934+
</maml:description>
10935+
</command:returnValue>
10936+
</command:returnValues>
10937+
<maml:alertSet>
10938+
<maml:alert>
10939+
<maml:para>Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/</maml:para>
10940+
</maml:alert>
10941+
</maml:alertSet>
10942+
<command:examples>
10943+
<command:example>
10944+
<maml:title>-------------------------- Example 1 --------------------------</maml:title>
10945+
<dev:code>PS C:\&gt; Test-EmptyFolder c:\work
10946+
False</dev:code>
10947+
<dev:remarks>
10948+
<maml:para>Test a single folder from a parameter.</maml:para>
10949+
</dev:remarks>
10950+
</command:example>
10951+
<command:example>
10952+
<maml:title>-------------------------- Example 2 --------------------------</maml:title>
10953+
<dev:code>PS C:\&gt; Get-Childitem c:\work -Directory | test-EmptyFolder -passthru
10954+
10955+
Path Name IsEmpty
10956+
---- ---- -------
10957+
C:\work\A A False
10958+
C:\work\alpha alpha False
10959+
C:\work\B B False
10960+
C:\work\data data False
10961+
C:\work\demo3 demo3 True
10962+
...</dev:code>
10963+
<dev:remarks>
10964+
<maml:para>Test child folders under C:\work.</maml:para>
10965+
</dev:remarks>
10966+
</command:example>
10967+
<command:example>
10968+
<maml:title>-------------------------- Example 3 --------------------------</maml:title>
10969+
<dev:code>PS C:\&gt; Get-Childitem c:\work -Directory | test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
10970+
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
10971+
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
10972+
What if: Performing the operation "Remove Directory" on target "C:\work\new".
10973+
What if: Performing the operation "Remove Directory" on target "C:\work\sqlback".
10974+
What if: Performing the operation "Remove Directory" on target "C:\work\todd".
10975+
What if: Performing the operation "Remove Directory" on target "C:\work\[data]".</dev:code>
10976+
<dev:remarks>
10977+
<maml:para>Find all empty sub-folders under C:\Work and pipe them to Remove-Item. This is one way to remove empty folders. The example is piping objects to ForEach-Object so that Remove-Item can use the -LiteralPath parameter, because C:\work[data] is a non-standard path.</maml:para>
10978+
</dev:remarks>
10979+
</command:example>
10980+
</command:examples>
10981+
<command:relatedLinks>
10982+
<maml:navigationLink>
10983+
<maml:linkText>Get-FolderSizeInfo</maml:linkText>
10984+
<maml:uri></maml:uri>
10985+
</maml:navigationLink>
10986+
</command:relatedLinks>
10987+
</command:command>
1083910988
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
1084010989
<command:details>
1084110990
<command:name>Test-Expression</command:name>

0 commit comments

Comments
 (0)