Skip to content

Commit

Permalink
v2.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Feb 26, 2020
1 parent cb4e02e commit bde14e8
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 22 deletions.
Binary file modified PSScriptTools.psd1
Binary file not shown.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,27 @@ Results will vary depending on whether you are running PowerShell on Windows nor

## File Tools

### [Test-EmptyFolder](docs/Test-EmptyFolder.md)

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.

```powershell
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
What if: Performing the operation "Remove Directory" on target "C:\work\new".
What if: Performing the operation "Remove Directory" on target "C:\work\sqlback".
What if: Performing the operation "Remove Directory" on target "C:\work\todd".
What if: Performing the operation "Remove Directory" on target "C:\work\[data]".
```

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.

### [Get-FolderSizeInfo](docs/Get-FolderSizeInfo.md)

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.
Expand Down Expand Up @@ -1145,6 +1166,6 @@ You will need to manually install the file.

## Compatibility

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.
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.

Last Updated *2020-02-12 19:38:27Z UTC*
Last Updated *2020-02-26 15:10:48Z UTC*
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log for PSScriptTools

## v2.17.0

+ Updated `Get-FolderSizeInfo` to handle directory names like `[data]` (Issue #65)
+ Updated `Get-FolderSizeInfo` to show a TotalSize of 0 for empty directories (Issue #64)
+ Cleaned up code in `Get-FolderSizeInfo` script file now that it is part of this module.
+ Added `Test-EmptyFolder`
+ Updated `README.md`

## v2.16.0

+ Fixed bug in `New-CustomFileName` when using a 24 hour value. (Issue #62)
Expand Down
6 changes: 4 additions & 2 deletions docs/Get-FolderSizeInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Get-FolderSizeInfo [-Path] <String[]> [-Hidden] [<CommonParameters>]

## DESCRIPTION

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.
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.

## EXAMPLES

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

### -Hidden

Include hidden directories
Include hidden directories.

```yaml
Type: SwitchParameter
Expand Down Expand Up @@ -122,6 +122,8 @@ http://jdhitsolutions.com/blog/essential-powershell-resources/

## RELATED LINKS

[Test-EmptyFolder]()

[Get-Childitem]()

[Measure-Object]()
128 changes: 128 additions & 0 deletions docs/Test-EmptyFolder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
external help file: PSScriptTools-help.xml
Module Name: PSScriptTools
online version:
schema: 2.0.0
---

# Test-EmptyFolder

## SYNOPSIS

Test if a folder is empty of files

## SYNTAX

```yaml
Test-EmptyFolder [-Path] <String[]> [-Passthru] [<CommonParameters>]
```

## DESCRIPTION

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.

## EXAMPLES

### Example 1

```powershell
PS C:\> Test-EmptyFolder c:\work
False
```

Test a single folder from a parameter.

### Example 2

```powershell
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru
Path Name IsEmpty
---- ---- -------
C:\work\A A False
C:\work\alpha alpha False
C:\work\B B False
C:\work\data data False
C:\work\demo3 demo3 True
...
```

Test child folders under C:\work.

### Example 3

```powershell
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
What if: Performing the operation "Remove Directory" on target "C:\work\new".
What if: Performing the operation "Remove Directory" on target "C:\work\sqlback".
What if: Performing the operation "Remove Directory" on target "C:\work\todd".
What if: Performing the operation "Remove Directory" on target "C:\work\[data]".
```

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.

## PARAMETERS

### -Passthru

Write a test object to the pipeline

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Path

Enter a file system path like C:\Scripts.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases: PSPath

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```

### CommonParameters

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).

## INPUTS

### System.String[]

## OUTPUTS

### Boolean

### EmptyFolder

## NOTES

Learn more about PowerShell:
http://jdhitsolutions.com/blog/essential-powershell-resources/

## RELATED LINKS

[Get-FolderSizeInfo]
()
155 changes: 152 additions & 3 deletions en-us/PSScriptTools-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4147,7 +4147,7 @@ Mode LastWriteTime Length Name
</maml:description>
</command:details>
<maml:description>
<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>
<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>
</maml:description>
<command:syntax>
<command:syntaxItem>
Expand All @@ -4167,7 +4167,7 @@ Mode LastWriteTime Length Name
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Hidden</maml:name>
<maml:Description>
<maml:para>Include hidden directories</maml:para>
<maml:para>Include hidden directories.</maml:para>
</maml:Description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
Expand All @@ -4181,7 +4181,7 @@ Mode LastWriteTime Length Name
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Hidden</maml:name>
<maml:Description>
<maml:para>Include hidden directories</maml:para>
<maml:para>Include hidden directories.</maml:para>
</maml:Description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -4279,6 +4279,10 @@ BOVINE320 D:\2016 5
<maml:linkText>Online Version:</maml:linkText>
<maml:uri>http://bit.ly/2RCoWQ6</maml:uri>
</maml:navigationLink>
<maml:navigationLink>
<maml:linkText>Test-EmptyFolder</maml:linkText>
<maml:uri></maml:uri>
</maml:navigationLink>
<maml:navigationLink>
<maml:linkText>Get-Childitem</maml:linkText>
<maml:uri></maml:uri>
Expand Down Expand Up @@ -10836,6 +10840,151 @@ WSMan:\
</maml:navigationLink>
</command:relatedLinks>
</command:command>
<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">
<command:details>
<command:name>Test-EmptyFolder</command:name>
<command:verb>Test</command:verb>
<command:noun>EmptyFolder</command:noun>
<maml:description>
<maml:para>Test if a folder is empty of files</maml:para>
</maml:description>
</command:details>
<maml:description>
<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>
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>Test-EmptyFolder</maml:name>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="0" aliases="PSPath">
<maml:name>Path</maml:name>
<maml:Description>
<maml:para>Enter a file system path like C:\Scripts.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Passthru</maml:name>
<maml:Description>
<maml:para>Write a test object to the pipeline</maml:para>
</maml:Description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Passthru</maml:name>
<maml:Description>
<maml:para>Write a test object to the pipeline</maml:para>
</maml:Description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName, ByValue)" position="0" aliases="PSPath">
<maml:name>Path</maml:name>
<maml:Description>
<maml:para>Enter a file system path like C:\Scripts.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
<dev:type>
<maml:name>System.String[]</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:inputType>
</command:inputTypes>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>Boolean</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:returnValue>
<command:returnValue>
<dev:type>
<maml:name>EmptyFolder</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
<maml:alertSet>
<maml:alert>
<maml:para>Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/</maml:para>
</maml:alert>
</maml:alertSet>
<command:examples>
<command:example>
<maml:title>-------------------------- Example 1 --------------------------</maml:title>
<dev:code>PS C:\&gt; Test-EmptyFolder c:\work
False</dev:code>
<dev:remarks>
<maml:para>Test a single folder from a parameter.</maml:para>
</dev:remarks>
</command:example>
<command:example>
<maml:title>-------------------------- Example 2 --------------------------</maml:title>
<dev:code>PS C:\&gt; Get-Childitem c:\work -Directory | test-EmptyFolder -passthru

Path Name IsEmpty
---- ---- -------
C:\work\A A False
C:\work\alpha alpha False
C:\work\B B False
C:\work\data data False
C:\work\demo3 demo3 True
...</dev:code>
<dev:remarks>
<maml:para>Test child folders under C:\work.</maml:para>
</dev:remarks>
</command:example>
<command:example>
<maml:title>-------------------------- Example 3 --------------------------</maml:title>
<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}
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
What if: Performing the operation "Remove Directory" on target "C:\work\new".
What if: Performing the operation "Remove Directory" on target "C:\work\sqlback".
What if: Performing the operation "Remove Directory" on target "C:\work\todd".
What if: Performing the operation "Remove Directory" on target "C:\work\[data]".</dev:code>
<dev:remarks>
<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>
</dev:remarks>
</command:example>
</command:examples>
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Get-FolderSizeInfo</maml:linkText>
<maml:uri></maml:uri>
</maml:navigationLink>
</command:relatedLinks>
</command:command>
<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">
<command:details>
<command:name>Test-Expression</command:name>
Expand Down

0 comments on commit bde14e8

Please sign in to comment.