Path length in function file() ?

Issues and Discussions related to Harbour

Moderator: Rathinagiri

Post Reply
dominique_devuyst
Posts: 14
Joined: Wed Dec 20, 2017 8:29 am
DBs Used: DBF
Location: Belgium
Has thanked: 12 times

Path length in function file() ?

Post by dominique_devuyst » Tue Apr 23, 2019 1:34 pm

Hello everybody,

It seems that the file() function does not accept a path longer than 56 characters?

example:
x := file ("c:\folder\subfolder\subfolder\somefile")
result --> x = .F. if length of c:\folder\subfolder\subfolder\ > 56

Windows 7 supports 260 characters, but I can not find any specification in the Harbour doc.

Somebody knows what?

User avatar
serge_girard
Posts: 2279
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 535 times
Been thanked: 114 times
Contact:

Post by serge_girard » Tue Apr 23, 2019 2:49 pm

Hi Dominque,

On w7 if tested a file of +100 len

Code: Select all

cFILE := 'P:\CDS\Allan Holdsworth-Alan Pasqua-Jimmy Haslip-Chad Wackerman\Blues for Tony Disc 1\01 Blues for Tony.WMA'
IF FILE(cFILE)
   MSGINFO('OK')
ELSE
   MSGINFO('NOK')
ENDIF
And it gave OK!

I'll try on my w10 later.

Serge

User avatar
serge_girard
Posts: 2279
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 535 times
Been thanked: 114 times
Contact:

Post by serge_girard » Tue Apr 23, 2019 3:10 pm

On w10 also OK!
Are you sure to check for the right filename?

Serge

User avatar
SALINETAS24
Posts: 321
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Has thanked: 13 times
Been thanked: 16 times

Post by SALINETAS24 » Tue Apr 23, 2019 4:31 pm

En xp es correcto

dominique_devuyst
Posts: 14
Joined: Wed Dec 20, 2017 8:29 am
DBs Used: DBF
Location: Belgium
Has thanked: 12 times

Post by dominique_devuyst » Tue Apr 23, 2019 5:18 pm

serge_girard wrote:
Tue Apr 23, 2019 3:10 pm
On w10 also OK!
Are you sure to check for the right filename?

Serge
Hello Serge,
Yes, I am sure. I have tested with a path of variable length by adding one character at a time and with always de same filename, len 15 characters.
file() return .T. but arrived at 56 characters the function returns .F.
I am on W7.
So, I will continue to search.
Dominique

edk
Posts: 448
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 133 times
Been thanked: 367 times

Post by edk » Tue Apr 23, 2019 6:36 pm

Please, do a simple test:

Code: Select all

#include "hmg.ch"
PROCEDURE Main
Local cPath := hb_CWD() + "folder 1234567890\ABCDEFGH ijklmn\123 456\__________\+_+_+_+_+_+_+_+_+_+_+_+_+_+\(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)\!@!@!@!@!@!@!@!@!\"
Local cFile := "test 1234567890 abc DEF.txt"

IF ! hb_DirBuild ( cPath ) 
	MsgStop ( "Error creating the folders." )
ENDIF
IF StrFile ( cPath + cFile, cPath + cFile ) < Len ( cPath + cFile )
	MsgStop ( "Error creating the file." )
ELSE
	MsgInfo ( "Your file: " + cPath + cFile )
ENDIF

MsgDebug ( "File():", File ( cPath + cFile ), "Len ():", Len ( cPath + cFile ) )
MsgDebug ( "hb_FileExists():", hb_FileExists ( cPath + cFile ), "Len ():", Len ( cPath + cFile ) )

Return

dominique_devuyst
Posts: 14
Joined: Wed Dec 20, 2017 8:29 am
DBs Used: DBF
Location: Belgium
Has thanked: 12 times

Post by dominique_devuyst » Wed Apr 24, 2019 2:05 pm

edk wrote:
Tue Apr 23, 2019 6:36 pm
Please, do a simple test:

Code: Select all

#include "hmg.ch"
PROCEDURE Main
Local cPath := hb_CWD() + "folder 1234567890\ABCDEFGH ijklmn\123 456\__________\+_+_+_+_+_+_+_+_+_+_+_+_+_+\(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)\!@!@!@!@!@!@!@!@!\"
Local cFile := "test 1234567890 abc DEF.txt"

IF ! hb_DirBuild ( cPath ) 
	MsgStop ( "Error creating the folders." )
ENDIF
IF StrFile ( cPath + cFile, cPath + cFile ) < Len ( cPath + cFile )
	MsgStop ( "Error creating the file." )
ELSE
	MsgInfo ( "Your file: " + cPath + cFile )
ENDIF

MsgDebug ( "File():", File ( cPath + cFile ), "Len ():", Len ( cPath + cFile ) )
MsgDebug ( "hb_FileExists():", hb_FileExists ( cPath + cFile ), "Len ():", Len ( cPath + cFile ) )

Return
Your example works fine, thank you.
Now I found the problem :
The pathname was not the problem but . . .
filename was not trimmed and with trailing blanks len (pathname + filename) > 260 :oops:
It's better just to laugh . . .

Dominique

edk
Posts: 448
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 133 times
Been thanked: 367 times

Post by edk » Wed Apr 24, 2019 3:00 pm

Sometimes it happens that an obvious mistake is difficult to notice. ;)

Post Reply