Skip to content

Instantly share code, notes, and snippets.

@frekac
Created December 15, 2016 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frekac/337b8d1b2abddffb2803f36d34d56b27 to your computer and use it in GitHub Desktop.
Save frekac/337b8d1b2abddffb2803f36d34d56b27 to your computer and use it in GitHub Desktop.
<#
.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