This project is read-only.

Powershell - how to use longPath in Remove-Item?

Oct 10, 2014 at 8:49 PM

I have sucessfully loaded assembly and I get the fill path of the so called "longPath">256 characters:

$AlphaFS = [System.Reflection.Assembly]::LoadFrom("D:\Dokumenty\WindowsPowershell\Modules\AlphaFS\AlphaFS.dll");

$p1 = "C:\abcdefghijklmnopqrssttuvwxyabcdefghijklmnopqrssttuvwxyabcdefghijklmnopqrssttuvwxyabcdefghijklmnopqrssttuvwxyabcdefghijklmnopqrssttuvwxyabcdefghijklmnopqrssttuvwxyabcdefghijklmnopqrssttuvwxyabcdefghijklmnopqrssttuvwxy"

$path1 = [Alphaleonis.Win32.Filesystem.Path]::GetFullPath($p1)

$file1 = ([Alphaleonis.Win32.Filesystem.Directory]::EnumerateFiles($p1,"*", [System.IO.SearchOption]::AllDirectories))

Do you have a clue how to use longPath in Remove-Item? It is possible?

Or I have to stick to everything from [Alphaleonis.Win32.Filesystem...] in order to preform all basic operations like copy,move,delete etc ?
Oct 10, 2014 at 9:08 PM

When using AlphaFS, you don't need to worry about long paths, meaning that all methods that
you call from AlphaFS will take care of long paths and full paths automatically.

However, you can not mix it with PowerShell commands because PowerShell also suffers from PATH TOO LONG.

Instead of Remove-Item you would use:
// Delete directory.

// Delete file.
Also, take a look at this post: Powershell 3.0 Support?
Here, in PowerShell, I dynamically define AlphaFS.dll when it is found, if not it falls back on System.IO