Skip to content

Commit

Permalink
Version 1.5
Browse files Browse the repository at this point in the history
added Get-PsOneDirectory and Install-LongPathSupport
  • Loading branch information
TobiasPSP committed Nov 30, 2019
1 parent a27d630 commit b72c9e5
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
84 changes: 84 additions & 0 deletions PSOneTools/1.5/Get-PSOneDirectory.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
function Get-PSOneDirectory
{
<#
.SYNOPSIS
Lists the content of a folder and supports long path names (>256 characters)
.DESCRIPTION
Uses the Microsoft.Experimental.IO assembly to list folder contents without
path name length limitations. You can use this function to search for and identify
files and folders that use long path names.
.EXAMPLE
Get-PSOneDirectory -Path C:\Windows -ErrorAction SilentlyContinue
Dumps the entire content of the windows folder and reports all files
and folders and their path length. Error messages due to folders
where you have no access permissions are suppressed.
.EXAMPLE
Get-PSOneDirectory -Path C:\Windows -ErrorAction SilentlyContinue |
Where-Object PathLength -gt 200
Lists files and folders with a path length of greater than 200 characters.
Error messages due to folders where you have no access permissions are suppressed.
.LINK
https://powershell.one/tricks/assemblies/load-from-memory
https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.5/Get-PSOneDirectory.ps1
https://github.com/TobiasPSP/Modules.PSOneTools/blob/master/PSOneTools/1.5/Internal/Install-LongPathSupport.ps1
#>


[CmdletBinding()]
param
(
# Folder path to enumerate
[Parameter(Mandatory)]
[string]
$Path
)

# load DLL if not loaded yet
# I am loading the DLL on demand because it is seldom used
# and should only be loaded when someone wants to run
# this function:
& "$PSScriptRoot\Internal\Install-LongPathSupport"

# emit the path and its length:
[PSCustomObject]@{
PathLength = $path.Length
Type = 'Folder'
Path = $Path
}

# try and enumerate subfolders:
try
{
[Microsoft.Experimental.IO.LongPathDirectory]::EnumerateDirectories($Path) |
ForEach-Object {
# recursively enumerate child folders:
Get-PSOneDirectory -path $_
}
}
catch
{
Write-Error "Unable to open folder '$Path': $_"
}

# try and enumerate files in folder
try
{
# get all files from current folder:
[Microsoft.Experimental.IO.LongPathDirectory]::EnumerateFiles($Path) |
ForEach-Object {
[PSCustomObject]@{
PathLength = $_.Length
Type = 'Folder'
Path = $_
}
}
}
catch
{
Write-Error "Unable to open folder '$Path': $_"
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions PSOneTools/1.5/Internal/Install-LongPathSupport.ps1

Large diffs are not rendered by default.

Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions PSOneTools/1.4/module.psm1 → PSOneTools/1.5/module.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
. $PSScriptRoot\Test-PSOneScript.ps1
. $PSScriptRoot\Get-PSOneToken.ps1
. $PSScriptRoot\Expand-PSOneToken.ps1
. $PSScriptRoot\Get-PSOneDirectory.ps1




0 comments on commit b72c9e5

Please sign in to comment.