This project is read-only.

Continue on Error - FileSystem.Directory

Mar 19, 2012 at 5:15 PM

I'm using the following command within a PowerShell script to generate an array (Thanks to Geoff Guynn for this).

$Files = [Alphaleonis.Win32.FileSystem.Directory]::GetFiles($TargetFolder, $strSearchFilter, $enumSearchOption) | Where {$_.LastWriteTime -le "$LastWrite"} | ? {$_ -match ("^.*\.asd|tmp$")}

The rest of the program checks each $file within $files and if the path > 260 it throws an error and then moves on to the next file, otherwise it logs the file name to a file, counts the number of files and shows how much space would be generated if the files were deleted.

My current problem is that if the command listed above finds a folder it can't access, the command stops (the rest of the program still runs) is there a way to:

- Get this command to move on to the next folder rather than just stopping.

- Log the error and even better list the folder it couldn't access.

I'm new to this so please assume I know nothing regarding PowerShell and AlphalFS (you won't be far from the truth!)

Thanks for any help provided.

Pete.

Mar 22, 2012 at 4:03 PM

You will need to use the following method from Directory class.

public static IEnumerable<FileSystemEntryInfo> GetFullFileSystemEntries(
          KernelTransaction transaction,
          string directory,
          string searchPattern,
          SearchOption searchOption,
          bool directoriesOnly,
          DirectoryEnumerationExceptionHandler handler,
          IList<Type> suppressedExceptions)

 

Did not play with Powershell yet, but something along those lines, the trick is to make the handler return 0 or, EnumerationExceptionDecision.Skip

To get to paths beyond 260, you can use Path.GetLongPath().

You may also check for what kind of exception was it and act accordingly.

That sample is not working as the anonymous handler part needs to be re-written to a correct format.

> PS alphafs\Development\Bin\Debug> Add-Type -Path .\AlphaFS.dll

> [Alphaleonis.Win32.FileSystem.Directory]::GetFullFileSystemEntries(null, @"C:\Temp", "*", 1, 0, {param($path, $e); return 0;}, null)

 

Mar 22, 2012 at 5:30 PM

Hi Normalex

Thanks for the email.

I tried the following code within Powershell

Add-Type -Path "c:\AlphaFS\AlphaFS.dll"

$Files=""

$Files = [Alphaleonis.Win32.FileSystem.Directory]::GetFullFileSystemEntries(null, "C:\Temp", "*", 1, 0, {param($path, $e); return 0;},null)

And get the following error:

Missing ')' in method call.

At C:\Scripts\FromNormalex.ps1:4 char:77

+ $Files = [Alphaleonis.Win32.FileSystem.Directory]::GetFullFileSystemEntries(

<<<< null, "C:\Temp", "*", 1, 0, {param($path, $e); return 0;},null)

+ CategoryInfo : ParserError: (CloseParenToken:TokenId) [], Parse

Exception

+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

I can’t see where there is a missing ‘)’ as they all seem to be paired to me. Any help greatly appreciated. Also, would this line include subfolders?

Pete.

Please don't print this e-mail unless you really need to. Help protect our environment.

From: normalex [email removed]
Sent: 22 March 2012 15:03
To: Peter Leeman
Subject: Re: Continue on Error - FileSystem.Directory [alphafs:349195]

From: normalex

You will need to use the following method from Directory class.

public static IEnumerable<FileSystemEntryInfo> GetFullFileSystemEntries(
KernelTransaction transaction,
string directory,
string searchPattern,
SearchOption searchOption,
bool directoriesOnly,
DirectoryEnumerationExceptionHandler handler,
IList<Type> suppressedExceptions)

Did not play with Powershell yet, but something along those lines, the trick is to make the handler return 0 or, EnumerationExceptionDecision.Skip

To get to paths beyond 260, you can use Path.GetLongPath().

You may also check for what kind of exception was it and act accordingly.

That sample is not working as the anonymous handler part needs to be re-written to a correct format.

> PS alphafs\Development\Bin\Debug> Add-Type -Path .\AlphaFS.dll

> [Alphaleonis.Win32.FileSystem.Directory]::GetFullFileSystemEntries(null, @"C:\Temp", "*", 1, 0, {param($path, $e); return 0;}, null)



SAVE PAPER - Please do not print this e-mail unless absolutely necessary



******** The Moray Council: Internet E-mail Notice ********

Moray Council Web address: http://www.moray.gov.uk
Main switchboard: 01343 543451

The contents of this e-mail and any attachments ('this e-mail') are confidential and intended solely for the addressee.
If this e-mail has been sent to you by mistake, please notify postmaster@moray.gov.uk as soon as possible; you should then delete this e-mail from your computer.
Developer
Aug 22, 2012 at 4:11 PM

Hi,

The error is generated due to the fact that PowerShell doesn't know null

Specify $null and it'll work!