It is currently Mon Nov 20, 2017 1:04 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Long Path Support
PostPosted: Wed Oct 18, 2017 3:57 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Oct 21, 2010 9:46 pm
Posts: 112
As per this doc:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

It should be possible to deal with filesystem paths that are over the old 260 character limit by prepending "\\?\" to the path (or using recent Win10 builds, but assume for the moment that we're not)

E.g. This path is invalid:

Code:
C:\Users\Username\Long Path Test\LongFolderName\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername


But by changing it to this, it should work:

Code:
\\?\C:\Users\Username\Long Path Test\LongFolderName\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername\Anotherlongfoldername


However, although I find that such paths do work as far as ExamineDirectory() etc are concerned - I can scan such folder structures and their contents fine, and copy files out of such long paths - things go amiss when trying to use CreateDirectory() to create them.

Using CreateDirectory on "Long Path Test" and each subfolder in turn eventually results in an apparent success, but the actual folder name created is truncated, and comes out as "Anotherlon". Looking at the entire resulting path, I find it's 257 characters, which is suspiciously close to the old 260 limit. All the subsequent folders fail with the error that there already is a folder of that name.

Has anyone done something similar where CreateDirectory has been used with such long paths? Anything extra you had to do to get it to work?

(These are test folder structures to explore the problem, but the purpose of the program involves syncing data from A to B, and I don't get to choose whether there are long paths on the source. So "don't have long paths" isn't a good option.)

(If you need to create such structures for testing purposes, md "\\?\C:\whatever\folder\you\want" works.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Long Path Support
PostPosted: Wed Oct 18, 2017 7:11 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 20, 2012 8:09 pm
Posts: 248
I was going to say, if MD \\?\ works on long names then just run command prompt for that command.
It didn't work for me.
I tried "md \\?\E:\longpath\....." and I got an error "is too long".

I know I have done it with C, I will see if I can find the code.


Norm.

_________________
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari


Top
 Profile  
Reply with quote  
 Post subject: Re: Long Path Support
PostPosted: Wed Oct 18, 2017 7:50 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 20, 2012 8:09 pm
Posts: 248
This works on my windows 7pro.
PB 5.60 or enable unicode if you have an older version.
You have to create the path one directory at at time. ( just like createdirectory() )

fname
Code:
fname$="\\?\e:\Users\Username\Long Path Test\LongFolderName\Anotherlongfoldername\..etc..\"
 Debug CreateFile_(fname$,#GENERIC_WRITE, 0,#Null, #CREATE_ALWAYS,#FILE_ATTRIBUTE_NORMAL , #Null)



[EDIT] added the relevant code.

Norm.

_________________
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari


Top
 Profile  
Reply with quote  
 Post subject: Re: Long Path Support
PostPosted: Fri Oct 20, 2017 11:24 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Oct 21, 2010 9:46 pm
Posts: 112
Well, I've made some progress, and I'm starting to think this is a bug in PB's CreateDirectory().

Using CreateDirectory() results in the creation of a folder with a truncated name, if LongPath$ is over 260 chars or so:

Code:
CreateDirectory(LongPath$)


But using the Windows API call directly works fine:

Code:
CreateDirectory_(LongPath$, #NUL)


(In all cases, LongPath$ is using the "\\?\" prefix)

Some of the other FileSystem functions also behave strangely. E.g., FileSize(LongPath$) returns -2 (indicating a directory) if the truncated form of LongPath$ exists, but the long version doesn't, again implying that it's doing its own truncation of the path. I suspect I can get something that works by using the native APIs in each case rather than the PB versions, but that's getting a bit messy.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye