News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

MAX_PATH

Started by jj2007, May 09, 2024, 10:53:07 PM

Previous topic - Next topic

jj2007

Is it 260 bytes or 260 chars?

Knowing that a Utf-8 character can be 4 bytes, it's not a trivial question.

Google finds quite a number of ambiguous posts for "max_path" "utf-8" "bytes" "chars", so I decided to test it on Win10:


Pseudocode:
include \masm32\MasmBasic\MasmBasic.inc
  Init
  GetFiles "\Masm32\MasmBasic\Misc\Let's have some fun with an incredibly long folder name that clearly exceeds the official MAX_PATH limitation imposed by Windows 7 and other not so recent versions of Windows that could possibly be present on a computer\*.*"
  For_ ecx=0 To eax-1 ; print the results
Print GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$
Print Str$(Len(Files$(ecx))), Spc2$
PrintLine Mid$(Files$(ecx), 235)
  Next
EndOfCode

Output:
06.11.2019  15:21:56    258  computer\MyExtraLong.asc
06.11.2019  15:59:48    258  computer\MyExtraLong.zip
06.11.2019  15:23:36    257  computer\MyLongTest.asc
06.11.2019  16:01:27    257  computer\MyLongTest.zip
24.11.2023  16:58:23    255  computer\Tmp_File.exe
09.05.2024  13:04:51    277  computer\Добропожаловать.txt
23.11.2023  16:59:11    268  computer\صندوق رسالة.asc
23.11.2023  16:58:04    268  computer\صندوق رسالة.asm
23.11.2023  16:58:33    268  computer\صندوق رسالة.exe

So apparently it's chars, not bytes. Tested, btw, also with Explorer, which refuses to add another char to that 277 bytes path. I find that a bit odd, it basically means that Windows doesn't check for the max number of bytes that fit into a buffer but rather calculates the #Utf-8 chars, and then decides how much buffer it needs...

sinsi

🍺🍺🍺

NoCforMe

Quote from: sinsi on May 09, 2024, 10:59:16 PMHa! Nothing so simple, sucker  :badgrin:
Maximum Path Length Limitation
First of all, excellent question.

From that article (on Micro$oft Learn if you didn't look at it):
QuoteThe Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters.
Now I wouldn't necessarily take that to the bank, but it implies that the actual MAX_PATH, at least for Unicode, is 32,767. Or may be that long. Or something.

Anyone care to generate a pathname that long and try it?
Assembly language programming should be fun. That's why I do it.

zedd151

#3
Quote from: NoCforMe on May 10, 2024, 05:06:48 AMAnyone care to generate a pathname that long and try it?
No, but I tried for surpassing 260...

I made 22 nested folders  (folder number 22, folder number 21, folder number 20, etc... {the innermost folders were named "number5, 4, 3, 2,1" }). The innermost folder had a single text file.
Windows changed the paths to 8.1 names... (in Windows 7 --> path copied from address bar in windows explorer) I added the txt file name for illustrative purposes.
QuoteC:\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\number5\4\3\2\1\thetext.txt
:cool:
Ventanas diez es el mejor.  :azn:

NoCforMe

Quote from: sudoku on May 10, 2024, 05:38:43 AMWindows changed the paths to 8.1 names... (in Windows 7 --> path copied from address bar in windows explorer)
You mean 8.3.

But why would it do that, unasked for by you? That seems weird.
So how long was the final pathname, total? (Going by what you quoted there, my editor tells me it's 183 characters, not even close to MAX_PATH.)
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on May 10, 2024, 05:50:58 AMYou mean 8.3.
Of course. Its been so long that I even had to refer to that.  :tongue:

Quote from: NoCforMe on May 10, 2024, 05:50:58 AMBut why would it do that, unasked for by you? That seems weird.
So how long was the final pathname, total? (Going by what you quoted there, my editor tells me it's 183 characters, not even close to MAX_PATH.)


After I select "Copy address as text" in the address bar in Windows explorer, thats what is copied...
QuoteC:\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\FOLDER~1\number5\4\3\2\1
Don't know why. And no I did not request that anywhere.

I tried it again to be sure the first time wasnt a fluke.
Ventanas diez es el mejor.  :azn:

zedd151

Quote from: NoCforMe on May 10, 2024, 05:50:58 AMSo how long was the final pathname, total?

315 characters:

No,  --- > correction 311 bytes... accidentally put spaces in "folder number9\folder number8\folder number7\folder number6" between "number" and the number...

The corrected path:
C:\folder number 22\folder number 21\folder number 20\folder number 19\folder number 18\folder number 17\folder number 16\folder number 15\folder number 14\folder number 13\folder number 12\folder number 11\folder number 10\folder number9\folder number8\folder number7\folder number6\number5\4\3\2\1\thetext.txt
Ventanas diez es el mejor.  :azn:

jj2007

Quote from: sinsi on May 09, 2024, 10:59:16 PMHa! Nothing so simple, sucker  :badgrin:
Maximum Path Length Limitation

Clear as mud :thumbsup:

The Unicode limit of 32767 is well-known but how can you actually use it if Explorer itself surrenders at around 260 characters?

jj2007

Quote from: sudoku on May 10, 2024, 05:38:43 AMpaths.zip

Nice, it does extract fine, but when you double-click, in the original Windows Explorer provided by Micros*t, on thetext.txt, you see an error message: invalid folder name :cool:

Clicking in file properties reveals that the path is 257 chars long:
\\?\D:\folder number 22\folder number 21\folder number 20\folder number 19\folder number 18\folder number 17\folder number 16\folder number 15\folder number 14\folder number 13\folder number 12\folder number 11\folder number 10\folder number9\folder number8

Oops, where are the folders after number 8?

Attempts to open thetext.txt result in a "folder name not valid" error box.

sinsi

Quote from: jj2007 on May 10, 2024, 06:39:35 AMThe Unicode limit of 32767 is well-known
But now there is a registry key (currently opt-in, which I'm sure will change), so you don't need the \\?\

Quote from: jj2007 on May 10, 2024, 06:39:35 AMExplorer itself surrenders at around 260 characters?
QuoteThe shell and the file system have different requirements. It is possible to create a path with the Windows API that the shell user interface is not able to interpret properly.
Good place to hide your porn :biggrin:
🍺🍺🍺

NoCforMe

Can I publish my short story as a pathname?
I guess it won't work for my novel.
Assembly language programming should be fun. That's why I do it.

zedd151

#11
 
Quote from: jj2007 on May 10, 2024, 06:45:54 AMAttempts to open thetext.txt result in a "folder name not valid" error box.
I Just extracted the contents of paths.zip to "C:" and it extracts fine (with 7zip), and all folders are present. The file opens okay in notepad as well.


But making and running a small test program with that path gives an error. CreateFile returns -1
Ventanas diez es el mejor.  :azn:

jj2007

Quote from: NoCforMe on May 10, 2024, 07:12:21 AMCan I publish my short story as a pathname?

If you can convince CreateFileW to accept a 32,767 character path, why not?

Quote from: sudoku on May 10, 2024, 07:23:22 AMThe file opens okay in notepad as well

Interesting: if you right-click and choose "Open", it fails. If you choose "Open with...", it opens with Notepad. It opens (and saves!) even with RichMasm. Only my MRU menu is not working.

Btw copy & paste of the file in Explorer doesn't work.

sinsi

QuoteThe Windows API has many functions that also have Unicode versions to permit an extended-length
path for a maximum total path length of 32,767 characters.
This type of path is composed of components separated by backslashes,
each up to the value returned in the lpMaximumComponentLength parameter of
the GetVolumeInformation function (this value is commonly 255 characters).
So you are still limited, as far as directory names go.
🍺🍺🍺

NoCforMe

Quote from: sinsi on May 10, 2024, 07:35:19 AMSo you are still limited, as far as directory names go.
Ackshooly:
QuoteWhen using an API to create a directory, the specified path cannot be so long that you cannot append an 8.3 file name (that is, the directory name cannot exceed MAX_PATH minus 12).
so it would seem that MAX_FOLDER_NAME would be 248 ...
Assembly language programming should be fun. That's why I do it.