Recent

Author Topic: [SOLVED] Is there a ForceDirectories and CopyFile that allows 32K length?  (Read 5909 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Further to the following:
http://stackoverflow.com/questions/6996711/how-to-create-directories-in-windows-with-path-length-greater-than-256
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_28013707.html
http://bugs.freepascal.org/view.php?id=24885
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath
http://www.freepascal.org/docs-html/rtl/sysutils/createdir.html and
http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/createdirutf8.html

In brief, I use ForceDirectoriesUTF8 from fileutil.inc, which utilises CreateDirUTF8 to create directories. And I use FileUtil.CopyFile to copy a file from one directory to another. Works great.

However, as many of us know and as the threads pasted above explain, any directory length of > 260 chars on Windows will cause errors due to the level set by MAX_PATH. But, NTFS allows lengths of around 32,767 chars, due to the need for Unicode etc. So, by use of CreateFileW, it is possible to create file and directory names much longer than 260 chars :

CreateFile :

In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming Files, Paths, and Namespaces.

My question is, using Lazarus 1.2.6 and FPC 2.6.4 (which I use as my stable programming environment), is there a way to avoid the ANSI limitation of 260 chars? I know it is possible to use CreateFileW combined with prepending paths with \\?\D:\MyDestination but it makes it much more complicated than my current simple implementation of :

if not CreateDirectoryUTF8(MyDestination) then ....

I was hoping there miught be a function somewhere that I can call that basically tells my program to tell Windows "We're not using the ANSI limit length of 260 - we're using the Unicode 32K limit".

Thanks
« Last Edit: September 24, 2015, 03:51:09 pm by Gizmo »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12984
  • FPC developer.
No. Trunk is a lot better though, many functions there use -W functions under the hood.

Bart

  • Hero Member
  • *****
  • Posts: 5757
    • Bart en Mariska's Webstek
You might try prepending the (fully expande path) with '\\?\'

Bart

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Bart

Yep - that worked :-) Thanks a million.

Paulina

  • Newbie
  • Posts: 1
I reccomend Long Path Tool. It helped me.

 

TinyPortal © 2005-2018