0

In Powershell I created a path, longer than the 260 character limit. E.g. a 305 character path as shown below.

cd /
mkdir A_100_____123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_
cd A_100*
mkdir B_100_____123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_
cd B_100*
mkdir C_100_____123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_
cd C_100*

But Explorer does not let me.

If I try to insert or create a file with a path longer than 260 characters, I get: "The file name(s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorter path. "

enter image description here

If I try to rename any file or folder with a path longer than 260 characters, I get "The file name you specified is not valid or too long. Specify a different file name.".

enter image description here

I ran into this because I had a script that happened to create a very long path, without being stopped from doing that. Is this an issue with Powershell? Or an issue with Explorer? Or perhaps neither?

I have a script that may create very long paths, and apparently nothing stops it from creating paths longer than 260 characters. My script is written in sh and running in WSL, but it could just as well have been written as a Powershell script.

Should I stop my script from doing that? If yes, is it then really my job as the script programmer to make such checks?

I'm running Windows 10 enterprise [Version 10.0.19045.3803].

Mads Skjern
  • 1,479
  • Yes; It’s your job as a programmer to place boundaries on a script. Just as you should be adding in error checking. – Ramhound Jan 03 '24 at 12:52
  • How would you set up this particular boundary on a PowerShell script? Its possible by making at least two checks (file name length and path length) for every operation that creates or moves a node in the file system. That would add 25-100% more lines to almost all scripts. Any script that adds or modifies a filesystem node has the potential to exceed the 260 limit. Maybe there is a better way of setting this particular boundary? – Mads Skjern Jan 03 '24 at 15:17

0 Answers0