Seite 1 von 2
DeleteDirectory Pfad >255
Verfasst: 13.03.2013 20:10
von lite
Hallo
Mir ist was merkwürdiges aufgefallen.
Bei Pfadlängen von über 255 Zeichen in einem Pfad stürzt Purebasic mit "ungültiger Speicherzugriff" ab.
Sollte da nicht statt einem Absturz Returncode 0 kommen ?
Ist das ein Purebasic Bug ?
Hier das Beispiel:
Code: Alles auswählen
val$="C:\test\"
RET=DeleteDirectory(val$,"",#PB_FileSystem_Force|#PB_FileSystem_Recursive)
Debug ret
C:\test\ = beinhaltet zusatzliche Unterordner mit über 255 Zeichen
Grüsse
Lite
Re: DeleteDirectory Pfad >255
Verfasst: 13.03.2013 20:36
von TroaX
Das liegt daran, das der Wert (Also den String>255 Zeichen) nicht in den von PB dafür reservierten Speicherbereich passt. Da nicht PB auf diesen Umstand, sondern das OS darauf reagiert schmeißt es dein PB-Programm einfach mit Systemeigener Fehlermeldung raus. Das ist schon richtig so. Ist gerade bei tieferen Ordnerstrukturen echt ärgerlich. Aber ich denke man das kann man nicht so einfach ändern.
Re: DeleteDirectory Pfad >255
Verfasst: 13.03.2013 20:58
von _JON_
Wie erstellt man den so einen Ordner zum testen, der Windows Explorer lässt das gar nicht zu
Kompiliere mal als Unicode und probiere das hier:
Code: Alles auswählen
val$="\\?\C:\test\"
RET=DeleteDirectory(val$,"",#PB_FileSystem_Force|#PB_FileSystem_Recursive)
Debug ret
Re: DeleteDirectory Pfad >255
Verfasst: 13.03.2013 21:09
von helpy
Re: DeleteDirectory Pfad >255
Verfasst: 13.03.2013 21:20
von lite
So wird ein Ordner über 255 Zeichen erstellt:
Code: Alles auswählen
Procedure.s FileGetShortName(File$)
;
; converts a long path/filename to 8.3 format
;
len = Len(File$)
ShortName$ = Space(len)
If GetShortPathName_(File$,ShortName$,len)
ProcedureReturn ShortName$
Else
ProcedureReturn ""
EndIf
EndProcedure
Procedure DirCreate(path$)
RET= FileSize(path$)
If RET=-2: ProcedureReturn 1: EndIf
RET=0
If Right(path$,1) <> "\" : path$ + "\" : EndIf
Temp$ = ""
For x = 1 To CountString(path$,"\")
temp$ + StringField(path$,x,"\") + "\"
If FileSize(Temp$) = -1: RET=CreateDirectory(Temp$): EndIf
Next x
ProcedureReturn RET
EndProcedure
Dir$="C:\Intel4\aaaaa1222222222222222222222222\bbbbbb3333333333333333333333333333333333333333333333333333\cccccccggggggggggggggggggggggggggggggggggggggggggggggggggg\dddddd888888888888888888888888888888888888888888\eeeeeeehhhhhhhhhhhhhhhhhhhh\cccccccc\"
Debug Len(dir$)
DirCreate(Dir$)
short$=FileGetShortName(dir$)
Debug short$
Debug DirCreate(short$+"laenger255Zeichen")
Lite
Re: DeleteDirectory Pfad >255
Verfasst: 13.03.2013 21:31
von _JON_
FileGetShortName - aha so geht das also.
Ich konnte es reproduzieren mit PB 5.11b3 x86.
Die x64 Version gibt nett 0 zurück,wie es auch sein soll.
"\\?\" hat leider keinen Einfluss.
Solltest vielleicht doch mal im englischen Bug Forum rein stellen.
Re: DeleteDirectory Pfad >255
Verfasst: 13.03.2013 21:46
von _JON_
Code: Alles auswählen
Procedure DirDelete(path.s)
Protected SHFILE.SHFILEOPSTRUCT
With SHFILE
\hwnd = #Null
\wFunc = #FO_DELETE
\fFlags = #FOF_NOCONFIRMATION | #FOF_NOERRORUI
\pFrom = @path
EndWith
ProcedureReturn SHFileOperation_(SHFILE)
EndProcedure
DirDelete("C:\Intel4")
Das funktioniert

Re: DeleteDirectory Pfad >255
Verfasst: 13.03.2013 21:54
von lite
Hallo _Jon_
Danke, jetzt stürzt nix mehr ab.
Könnnte trotzdem jemand einen Bug-Report im englischen Forum machen ?
Grüße
Lite
Re: DeleteDirectory Pfad >255
Verfasst: 14.03.2013 08:44
von helpy
lite hat geschrieben:Hallo _Jon_
Danke, jetzt stürzt nix mehr ab.
Könnnte trotzdem jemand einen Bug-Report im englischen Forum machen ?
Grüße
Lite
Das Problem mit zu langen Verzeichnisnamen ist kein PureBasic spezifisches Problem.
Diese Einschränkung ist in den alten Windows API-Befehlen, wie es von Microsoft dokumentiert ist:
Microsoft MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#maxpath) hat geschrieben:Maximum Path Length Limitation
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string<NUL>" where "<NUL>" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)
Note File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections.
The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".
Note The maximum path of 32,767 characters is approximate, because the "\\?\" prefix may be expanded to a longer string by the system at run time, and this expansion applies to the total length.
The "\\?\" prefix can also be used with paths constructed according to the universal naming convention (UNC). To specify such a path using UNC, use the "\\?\UNC\" prefix. For example, "\\?\UNC\server\share", where "server" is the name of the computer and "share" is the name of the shared folder. These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.
There is no need to perform any Unicode normalization on path and file name strings for use by the Windows file I/O API functions because the file system treats path and file names as an opaque sequence of WCHARs. Any normalization that your application requires should be performed with this in mind, external of any calls to related Windows file I/O API functions.
When using an API to create a directory, the specified path cannot be so long that you cannot append an 8.3 file name (that is, the directory name cannot exceed MAX_PATH minus 12).
The shell and the file system have different requirements. It is possible to create a path with the Windows API that the shell user interface is not able to interpret properly.
Re: DeleteDirectory Pfad >255
Verfasst: 14.03.2013 10:02
von _JON_
helpy hat geschrieben:
Das Problem mit zu langen Verzeichnisnamen ist kein PureBasic spezifisches Problem.
Diese Einschränkung ist in den alten Windows API-Befehlen, wie es von Microsoft dokumentiert ist:
Es ist schon klar das die API hier ein Problem hat, aber die API würde deshalb eigentlich keinen Crash verursachen.
Darum wäre es besser wenn die PB-Entwickler mal drauf schauen ob in DeleteDirectory() nicht etwas falsch läuft.