/Get-FilesQuickIO.ps1 Secret
Created
December 15, 2016 19:33
Star
You must be signed in to star a gist
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
<# | |
.Synopsis | |
Search file structure using QuickIO.Net library | |
.DESCRIPTION | |
Search the file structure without the 260+ character path length limit. | |
.EXAMPLE | |
Get-FilesQuickIO -FilePath <path> -Filter "*.*" -Recursive | |
#> | |
function Get-FilesQuickIO | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
# Path to start from | |
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] | |
[string]$FilePath, | |
# To search recursively | |
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] | |
[switch]$Recursive, | |
# To filter | |
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] | |
[string]$Filter | |
) | |
# Load QuickIO Assmebly | |
Add-Type -Path .\QuickIO\SchwabenCode.QuickIO.dll | |
# Initiate the file list | |
$fileList = @() | |
# Set search option based on recursive or not | |
if(($Recursive -eq $true) -and (($Filter -eq "*") -or ($Filter -eq "*.*"))) | |
{ | |
# Set the search option value | |
$searchOption = "AllDirectories" | |
# Get the list of files | |
$fileList = [SchwabenCode.QuickIO.QuickIODirectory]::EnumerateFiles([system.string]$FilePath,[system.string]$Filter,[System.IO.SearchOption]$searchOption) | |
} | |
elseif ($Recursive -eq $true) | |
{ | |
# Set the search option value | |
$searchOption = "AllDirectories" | |
# Set the directory pattern | |
$directoryPattern = "*" | |
# Get all the directories as the recursive option doesn't work when using a filter. | |
$directoryList = [SchwabenCode.QuickIO.QuickIODirectory]::EnumerateDirectories([system.string]$FilePath,[system.string]$directoryPattern,[System.IO.SearchOption]$searchOption) | select -ExpandProperty FullName | |
# Loop through the directories with the file pattern | |
foreach($d in $directoryList) | |
{ | |
$fileList += try{[SchwabenCode.QuickIO.QuickIODirectory]::EnumerateFiles([system.string]$d,[system.string]$Filter,[System.IO.SearchOption]$searchOption)}catch{$null} | |
} | |
} | |
else{ | |
# Set the search option value | |
$searchOption = "TopDirectoryOnly" | |
# Get the list of files | |
$fileList = try{[SchwabenCode.QuickIO.QuickIODirectory]::EnumerateFiles([system.string]$FilePath,[system.string]$Filter,[System.IO.SearchOption]$searchOption)}catch{$null} | |
} | |
return $fileList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment