Modify

Opened 12 years ago

Closed 11 years ago

#2310 closed Bug (Rejected)

FileGetShortName result wrong for long filenames

Reported by: KaFu Owned by:
Milestone: Component: AutoIt
Version: 3.3.8.1 Severity: None
Keywords: Cc:

Description

The result returned by FileGetShortName seem wrong if the path is longer than 260 characters. Only a truncated result (273 characters) is returned, but @error = 0.

Here is a reproducer using WinApiEx.

#include <WinAPIEx.au3>

; REMOVE test files
$sDir_Source = "\\?\" & @ScriptDir & "\_Source"
If MsgBox(4, "", "Press YES to run test" & @CRLF & @CRLF & "Press NO to remove files from previous test") <> 6 Then
	For $i = 51 To 1 Step -1
		$sDir = $sDir_Source
		For $y = 1 To $i
			$sDir &= "\1234567890"
		Next
		ConsoleWrite($i & @TAB & $sDir & "\test.txt" & @CRLF)
		ConsoleWrite("FD: " & _FileDeleteEx($sDir & "\test.txt") & @CRLF)
		$iRes = _DirRemoveEx_Empty($sDir)
		ConsoleWrite(_WinAPI_GetLastErrorMessage() & @CRLF)
		ConsoleWrite("RD: " & FileExists($sDir) & @TAB & $iRes & @CRLF)
	Next
	DirRemove("\\?\" & @ScriptDir & "\_Source")
	Exit
EndIf

; CREATE test files
DirCreate("\\?\" & @ScriptDir & "\_Source")
$sDir = $sDir_Source
For $i = 0 To 50
	$sDir &= "\1234567890"
	_WinAPI_CreateDirectory($sDir)
	_Create_TestFile($sDir & "\")
Next

; PERFORM Test
$sDir = @ScriptDir & "\_Source\"
For $i = 0 To 50
	$sDir &= "1234567890\"
	$sFile = $sDir & 'test.txt'
	ConsoleWrite($i & @TAB & StringLen(FileGetShortName("\\?\" & $sFile)) & @TAB & FileGetShortName("\\?\" & $sFile) & @tab & @error & @CRLF)
	ConsoleWrite($i & @TAB & StringLen(_WinAPI_GetShortPathNameW("\\?\" & $sFile)) & @TAB & _WinAPI_GetShortPathNameW("\\?\" & $sFile) & @CRLF)
	ConsoleWrite("========" & @CRLF)
Next

Func _Create_TestFile($sDir)
	$sFile = $sDir & 'test.txt'
	Local $nBytes
	$sText = StringLen($sFile) & @CRLF & $sFile
	$tBuffer = DllStructCreate("byte[" & StringLen($sText) & "]")
	DllStructSetData($tBuffer, 1, $sText)
	$hFile = _WinAPI_CreateFile($sFile, 1)
	_WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer), StringLen($sText), $nBytes)
	_WinAPI_CloseHandle($hFile)
EndFunc   ;==>_Create_TestFile

Func _WinAPI_GetShortPathNameW($sPath)
	Local $rc = DllCall("kernel32.dll", "int", "GetShortPathNameW", "wstr", $sPath, "wstr", "", "int", 32768)
	Return $rc[2]
EndFunc   ;==>_WinAPI_GetShortPathNameW

Func _DirRemoveEx_Empty($sPath)
	Local $iRes = DllCall("kernel32.dll", "int", "RemoveDirectoryW", "wstr", $sPath)
	Return $iRes[0]
EndFunc   ;==>_DirRemoveEx_Empty

Func _FileDeleteEx($sFile)
	Local $iRes = DllCall("kernel32.dll", "int", "DeleteFileW", "wstr", $sFile)
	Return $iRes[0]
EndFunc   ;==>_FileDeleteEx

Attachments (0)

Change History (2)

comment:1 Changed 12 years ago by Jpm

the repro test can run only under 3.3.9.4 still true in the current next beta

comment:2 Changed 11 years ago by Jon

  • Resolution set to Rejected
  • Status changed from new to closed

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.