Powershell - how to use longPath in Remove-Item?

Oct 10, 2014 at 7:49 PM
Hi,

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 ?
Developer
Oct 10, 2014 at 8:08 PM
Hi!

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.
[Alphaleonis.Win32.Filesystem.Directory]::Delete($folder)

// Delete file.
[Alphaleonis.Win32.Filesystem.File]::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