Page 1 of 2

Len of path limit for FileSize() [Resolved]

Posted: Sun Dec 31, 2023 2:11 pm
by Kwai chang caine
Hello at all,

I don't understand why, but among 8 millions of elements in an USB hard disk, i have several lines who return -1, then that the file or folder exist :shock:
When i paste the full path in windows explorer that works, i see the file/folder and SileSize() return -1 :|
I have try with v5.73 and 6.02, and also on another machine it's the same thing
Furthermore the files and folders is read acces, it's the reason why i ask to me if there are a limit in the len of path :idea:

Code: Select all

File$ = "e:\A\A\B\A\O\Workspaces_Complets\workspacetizen du 180418\tizen-studio\tools\jsa\jalangi\node_modules\jalangi\node_modules\rewriting-proxy\node_modules\jsdom\node_modules\htmlparser2\node_modules\domutils\node_modules\dom-serializer\node_modules\domelementtype\"
Debug FileSize(File$)
Debug Len(File$)
Debugger wrote:-1
261
And if i try this code

Code: Select all

File$ = "e:\A\A\B\A\O\Workspaces_Complets\workspacetizen du 180418\tizen-studio\tools\jsa\jalangi\node_modules\jalangi\node_modules\rewriting-proxy\node_modules\jsdom\node_modules\htmlparser2\node_modules\domutils\node_modules\dom-serializer\node_modules\domelementtype\"
Debug OpenFile(0,File$)
Debug GetFileSize_(FileID(0),0)
CloseFile(0)
The debugger return 0 and i have an IMA on the "GetFileSize_()" line :|

Someone have an idea why that not works ?
Have a good day

Re: Len of path limit for FileSize()

Posted: Sun Dec 31, 2023 2:19 pm
by SPH
Bin, la longueur du chemin; je crois, est de 255 (voir même 25x ou 24x...)
En tout cas, j'ai toujours eu ça en tête ! :idea:

ps : j'ai les même valeurs que toi dans le débug

Re: Len of path limit for FileSize()

Posted: Sun Dec 31, 2023 3:08 pm
by Psychophanta
Kwai chang caine wrote: Sun Dec 31, 2023 2:11 pm When i paste the full path in windows explorer that works, i see the file/folder and FileSize() return -1 :|
My bet is the file library of PB does not allow so long path. Then the file or folder is not found.

Re: Len of path limit for FileSize()

Posted: Sun Dec 31, 2023 3:16 pm
by Kiffi
SPH wrote: Sun Dec 31, 2023 2:19 pm Bin, la longueur du chemin; je crois, est de 255 (voir même 25x ou 24x...)
En tout cas, j'ai toujours eu ça en tête ! :idea:

ps : j'ai les même valeurs que toi dans le débug
@SPH: This is an English-language forum.
SPH via DeepL wrote: Well, the path length, I believe, is 255 (or even 25x or 24x...).
Anyway, I've always had that in mind! :idea:

ps: I have the same values as you in the debug.

Re: Len of path limit for FileSize()

Posted: Sun Dec 31, 2023 4:31 pm
by boddhi
Salut @KCC

It depends on which Windows version too.
Remember this post

Bonnes fêtes :wink:

Re: Len of path limit for FileSize()

Posted: Sun Dec 31, 2023 5:26 pm
by Kwai chang caine
Thanks at all for your answer

@SPH
Hello visitor of my PC :mrgreen:
It's normal you have the same answer because i suppose you have not create all the tree structure in your machine :wink:
Remark, it's surely easy to create her, with the API :wink:

Code: Select all

SHCreateDirectory_(#Null, File$)
Yes i have thinking to this 255 number, but it's strange this time, because usually it's Windows who not works, not PB :shock:
Psychophanta wrote:My bet is the file library of PB does not allow so long path
You have surely right :|
But it's perhaps the time to try to enlarge this number no ?
Because if you watch better, my personal path is very small, only 55 characters
A\A\B\A\O\Workspaces_Complets\workspacetizen du 180418\
all the rest, everything else is a TIZEN software, and i can't do anythhing against that :oops:
And it's when even a pity to have a library who can't do all that Windows accept :(
Boddhi wrote:It depends on which Windows version too.
Hello :D
This time it's not Windows the problem, because i can access to the file/folder with him :wink:
You believe the PB function can accept more long path if the WINDOWS change ?
The more strange it's even the API not works, perhaps FRED use this API for FileSize()

@Thanks at all for your precious advice
Have a good end of year 8)

Re: Len of path limit for FileSize() [Resolved]

Posted: Mon Jan 01, 2024 1:30 pm
by Psychophanta
@Kwai chang caine,
as a workaround, if i had your problem, I would create a letter like U:, V:, etc. as an alias for a path, or part of a path.

Re: Len of path limit for FileSize() [Resolved]

Posted: Mon Jan 01, 2024 8:34 pm
by Kwai chang caine
It's a good idea, but in this case i don't believe it's posssible :|

Because i scan the full hard disk, so i begin to the path (More short you dead) "E:\" and in the middle of the 8 millions files/folder scan, i found this and others monstruous path :twisted:
It's not my fault, if several softwares have some path of folders too much long :oops:

And again, i replace all my personals folders names, to only one letter "E:\A\B\A\A\etc..." for not have this style of problem, and it's not always easy each days for find a file :lol: but apparently it's not enough :oops:
My wife say to me : "The day you die, I'll just have to throw away the hard drive in the trash !!" :mrgreen:
When i use comparator software like Beyound compare, never he say to me "The line is too long"
In fact only Windows say that to me usually, not PB :|

Re: Len of path limit for FileSize() [Resolved]

Posted: Mon Jan 01, 2024 9:23 pm
by AZJIO
Source of information
FindFirstFile
By default, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, prepend "\\?\" to the path. For more information, see Naming Files, Paths, and Namespaces.
Source of information
If path lengths > 260 chars, prefix path with "\\?\" - return paths are not affected

Code: Select all

File$ = "\\?\e:\A\A\B\A\O\Workspaces
Source of information
FindFirstFile / FindFirstFileW
There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the FindFirstFile function parses paths. An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of FindFirstFile and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing; it lets paths longer than MAX_PATH be used with FindFirstFileW. However, each component in the path cannot be more than MAX_PATH characters long. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\bill_g_1\hotstuff\coolapps" is seen as "\\bill_g_1\hotstuff\coolapps".

Re: Len of path limit for FileSize()

Posted: Mon Jan 01, 2024 10:32 pm
by ChrisR
Kwai chang caine wrote: Sun Dec 31, 2023 5:26 pm This time it's not Windows the problem, because i can access to the file/folder with him :wink:
You believe the PB function can accept more long path if the WINDOWS change ?
The more strange it's even the API not works, perhaps FRED use this API for FileSize()
https://learn.microsoft.com/en-us/windo ... s=registry
Or with automatic translation: https://learn.microsoft.com/fr-fr/windo ... s=registry
Enable Long Paths in Windows 10, Version 1607, and Later
Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.

To enable the new long path behavior, both of the following conditions must be met:

Code: Select all

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001

The application manifest must also include the longPathAware element.

Code: Select all

<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
        <ws2:longPathAware>true</ws2:longPathAware>
    </windowsSettings>
</application>
It shouldn't be a problem for you to change the LongPathsEnabled registry value with your magic fingers but waits until the champagne bubbles are gone :D
To change the manifest you can use Update Manifest in Executable or ResourceHacker.

Re: Len of path limit for FileSize() [Resolved]

Posted: Tue Jan 02, 2024 12:29 am
by AZJIO
Check on a long file path

Code: Select all

EnableExplicit
#FILE_ATTRIBUTE_ALL = #FILE_ATTRIBUTE_ARCHIVE | #FILE_ATTRIBUTE_ENCRYPTED | #FILE_ATTRIBUTE_HIDDEN | #FILE_ATTRIBUTE_NORMAL | #FILE_ATTRIBUTE_OFFLINE | #FILE_ATTRIBUTE_READONLY | #FILE_ATTRIBUTE_SYSTEM | #FILE_ATTRIBUTE_TEMPORARY

Procedure GetFileSize(File$)
	Protected hFile, Size = -1
	hFile = CreateFile_("\\?\" + File$, 0, 0, 0, #OPEN_EXISTING, #FILE_ATTRIBUTE_ALL, #NUL)
	If hFile <> #INVALID_HANDLE_VALUE And GetFileType_(hFile) = #FILE_TYPE_DISK
		Size = GetFileSize_(hFile, 0)
		CloseHandle_(hFile)
	EndIf
	ProcedureReturn Size
EndProcedure

Debug GetFileSize("C:\1.bmp")

Re: Len of path limit for FileSize() [Resolved]

Posted: Tue Jan 02, 2024 6:04 pm
by Kwai chang caine
Whaooouuuhhh !!!

ImageImage
AZJIO and ChrisR !!!!!
You are like two Christmas angels on his cloud, who come down from heaven, to perform a miracle at little KCC :shock: who is all alone in pain
:(

Honestly, I thought there was no solution, and yours ....works. :shock:
One thousand of thanks at you two 8)

Thanks a lot too, AZJIO for your miracle code, come to heaven :D

Code: Select all

EnableExplicit
#FILE_ATTRIBUTE_ALL = #FILE_ATTRIBUTE_ARCHIVE | #FILE_ATTRIBUTE_ENCRYPTED | #FILE_ATTRIBUTE_HIDDEN | #FILE_ATTRIBUTE_NORMAL | #FILE_ATTRIBUTE_OFFLINE | #FILE_ATTRIBUTE_READONLY | #FILE_ATTRIBUTE_SYSTEM | #FILE_ATTRIBUTE_TEMPORARY

Procedure GetFileSize(File$)
	Protected hFile, Size = -1
	hFile = CreateFile_("\\?\" + File$, 0, 0, 0, #OPEN_EXISTING, #FILE_ATTRIBUTE_ALL, #NUL)
	If hFile <> #INVALID_HANDLE_VALUE And GetFileType_(hFile) = #FILE_TYPE_DISK
		Size = GetFileSize_(hFile, 0)
		CloseHandle_(hFile)
	EndIf
	ProcedureReturn Size
EndProcedure

Debug GetFileSize("f:\A\A\B\A\O\Workspaces_Complets\workspacetizen du 180418\tizen-studio\tools\jsa\jalangi\node_modules\jalangi\node_modules\rewriting-proxy\node_modules\jsdom\node_modules\htmlparser2\node_modules\domutils\node_modules\dom-serializer\node_modules\domelementtype\LICENSE")
Compiler wrote:1260
I love you two !!!
Image
And make to you a big SMACK for your great present :mrgreen:
And i wish to you, the best good year of all the goods years of the world 8)

On the other hand, i have try for a folder, and that not works :|
After searching, i found this API who works, but it's perhaps not the best in my case :oops:

Code: Select all

Debug GetFileAttributes_("\\?\f:\A\A\B\A\O\Workspaces_Complets\workspacetizen du 180418\tizen-studio\tools\jsa\jalangi\node_modules\jalangi\node_modules\rewriting-proxy\node_modules\jsdom\node_modules\htmlparser2\node_modules\domutils\node_modules\dom-serializer\node_modules\domelementtype")
This code return -1 if the folder not exist, and i don't know Why, but the return of debugger is 8208 :shock:
I believed it's perhaps #FILE_ATTRIBUTE_DIRECTORY, but no, because #FILE_ATTRIBUTE_DIRECTORY = 16 :|

Re: Len of path limit for FileSize() [Resolved]

Posted: Tue Jan 02, 2024 8:26 pm
by firace
Kwai chang caine wrote: Tue Jan 02, 2024 6:04 pm

Code: Select all

Debug GetFileAttributes_("\\?\f:\A\A\B\A\O\Workspaces_Complets\workspacetizen du 180418\tizen-studio\tools\jsa\jalangi\node_modules\jalangi\node_modules\rewriting-proxy\node_modules\jsdom\node_modules\htmlparser2\node_modules\domutils\node_modules\dom-serializer\node_modules\domelementtype")
This code return -1 if the folder not exist, and i don't know Why, but the return of debugger is 8208 :shock:
I believed it's perhaps #FILE_ATTRIBUTE_DIRECTORY, but no, because #FILE_ATTRIBUTE_DIRECTORY = 16 :|
Hi KCC,
8208 is a combination of 2 attributes:
#FILE_ATTRIBUTE_NOT_CONTENT_INDEXED (8192) + #FILE_ATTRIBUTE_DIRECTORY (16)

See attribute values here:
https://learn.microsoft.com/en-us/windo ... -constants

Happy New Year!

Re: Len of path limit for FileSize() [Resolved]

Posted: Tue Jan 02, 2024 8:42 pm
by Kwai chang caine
Hello FIRACE
Thanks a lot for your usefull answer, i know why i have this value now 8)

Your answer reminds me of another question :oops:
How do you know the combination of constants, when you have the value ?
You tried all the possibilities or you knew the answer :wink:

Re: Len of path limit for FileSize() [Resolved]

Posted: Tue Jan 02, 2024 8:53 pm
by firace
Kwai chang caine wrote: Tue Jan 02, 2024 8:42 pm Hello FIRACE
Thanks a lot for your usefull answer, i know why i have this value now 8)

Your answer reminds me of another question :oops:
How do you know the combination of constants, when you have the value ?
You tried all the possibilities or you knew the answer :wink:
The values are hex flags, so one quick way to find what the attributes are is to convert 8208 to hex:

Code: Select all

 debug hex(8208)  ;; =>  2010  
2010 = 2000 + 10

Image

Image

(A better, more accurate way would be to AND 8208 with each possible flag)