-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Get-PsOneDirectory and Install-LongPathSupport
- Loading branch information
Showing
12 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters