FileCopy fails with long paths

Post bugreports for the Windows version here
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

FileCopy fails with long paths

Post by BarryG »

Since PureBasic is Unicode now, we need FileCopy() to work with long paths. Currently, it still fails if the destination file path is >260 characters, which I've just discovered with my own apps.

I found this post by normeus which fixes the issue -> https://www.purebasic.fr/english/viewto ... 79#p423879

Using his tip, I'm now using the following macro hack to "fix" FileCopy() in my sources. But can FileCopy() be fixed to do this instead? Thanks!

Code: Select all

Macro FileCopy(source,dest)
  FileCopy("\\?\"+source,"\\?\"+dest)
EndMacro
And possibly related: DeleteDirectory() isn't deleting a folder path on my PC that has >260 chars:

Code: Select all

; Don't run this as-is because it will delete data on your PC!
; Debug DeleteDirectory(path_over_260_chars$,"",#PB_FileSystem_Recursive|#PB_FileSystem_Force) ; Returns 0
Prefixing the path with "\\?\" doesn't make it work.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: FileCopy fails with long paths

Post by jacdelad »

If I remember right windows has several problems with patnames >260 characters. That's why API calls don't work with them.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: FileCopy fails with long paths

Post by Fred »

Makes sense, as it's an unicode only feature. According to https://docs.microsoft.com/en-us/window ... reatefilea it should be the correct way to add 32k long path support.
Post Reply