Thanks to bad, old code, Microsoft’s PowerShell breaks on file or directory paths longer than 248 characters. PowerShell reuses other code that maintains compatibility with very old software that can’t understand paths with more than 260 characters. I don’t know how 260 drops to 248 in PowerShell, but it does.
Amazingly, in the first comment in a bug report, Microsoft dodges the question and passes the buck.
I hit this bug when working with a Sitecore web site. For example, I have a path like this:
C:\XXXXXXXXXXXXXXX\raw\WebSite\App_Data\MediaFiles\{11111111-1111-1111-1111-111111111111}\{3D6658D8-A0BF-4E75-B3E2-D050FABCF4E1}\{15451229-7534-44EF-815D-D93D6170BFCB}\{700C2C14-6082-4378-AA43-821E8422E9BE}\{6507E0E5-6CF2-4342-A11F-68F787B32EA3}Boulevard.jpg
That is 259 characters. I can’t delete it with PowerShell’s Remove-Item command.
Fortunately, there is a workaround: use legacy command prompt tools. In my case, I am trying to remove everything below C:\XXXXXXXXXXXXXXX\raw\, so I can use this command in PowerShell:
cmd /c rmdir C:\XXXXXXXXXXXXXXX\raw\ /s/q
But I shouldn’t have to do this. There is no reason that PowerShell can’t delete files with more than 248 character paths.
RMDIR is also limited to MAX_PATH (260 chars), so it is not really a solution to the problem of how to remove files/directories with long paths. It just gets you 12 characters further in PowerShell.
I’m a french user and i’have the same problem.
But when I use “Map network Drive” I can use a Drive , mapping to folder with long path (Under 248 caracters) .
Ex :
Drive D:
Folder : Abcdef ………..\agft …..\……….
After under Windows Explorer i can delete file and folders under Drive D (in this exemple).
Under DOS it’s works too.
In poweshell I try to use PS-Drive to map a Folder with long path (Under 248 caracters) and after deleting files (like with windows).
It’s doesn’t work.
I received the bul….. message :
“The specified path, file name, or both are too long. The fully
qualified file name must be less than 260 characters, and the directory name must be less than 248 characters”.
Where is my mistake ?
Is it work or not.
long path tool can helpful on this situation.
I’m happy to know that.
But may we have a link to see this wonderful tools.
Regards.
Hi,
PowerShell can easily be used with AlphaFS.dll to do actual file I/O stuff
without the PATH TOO LONG hassle.
For example:
Import-Module
[Alphaleonis.Win32.Filesystem.Directory]::Delete($path, $True)
Please see at Codeplex: https://alphafs.codeplex.com/ for this .NET project.
Long Path Tool helped me out in this situation, thanks for the reply
it works for me thank you very mutch.
Anyone has an idea of this ?
https://answers.microsoft.com/en-us/windows/forum/windows8_1-winapps/powershell-help-in-kor-cht-chs-inserts-unexpected/41086aac-f8de-4547-8e05-9d5eb8b1f6cb?tm=1476872255145
I replied to this in the Microsoft answer page. Wish you a good time here!
Try use:
Remove-Item “\\?\C:\XXXXXXXXXXXXXXX\raw\WebSite\App_Data\MediaFiles\{11111111-1111-1111-1111-111111111111}\{3D6658D8-A0BF-4E75-B3E2-D050FABCF4E1}\{15451229-7534-44EF-815D-D93D6170BFCB}\{700C2C14-6082-4378-AA43-821E8422E9BE}\{6507E0E5-6CF2-4342-A11F-68F787B32EA3}Boulevard.jpg” -Force
I would suggest to try “Long Path Tool” program.