PDA

View Full Version : File.GetShortName() on already short names.



jassing
03-09-2010, 10:38 AM
See the image -- when using short names to File.GetShortName() I'm getting garbage...

RizlaUK
03-10-2010, 03:34 PM
god d.a.m man, how short do you want that path :p

if using the API direct it works ok, so its an AMS bug for sure, and i guess bugs need fixing

here, try THIS air code :D

function GetShortPath(sPath)
local _LongPath = Memory.Allocate(1024);
local _ShortPath = Memory.Allocate(1024);
Memory.PutString(_LongPath, sPath, -1, "Ascii");
local ret = DLL.CallFunction("Kernel32.dll", "GetShortPathNameA", _LongPath..",".._ShortPath..",1024", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
local sShortPath = Memory.GetString(_ShortPath, -1, "Ascii");
Memory.Free(_LongPath);
Memory.Free(_ShortPath);
return sShortPath
end

sLong="C:\\Users\\Dean\\Documents\\Battlefield Heroes\\PersistentStorage.dat"
sShort=GetShortPath(sLong)
Dialog.Message("Notice", sShort);
Dialog.Message("Notice", GetShortPath(sShort));

jassing
03-10-2010, 05:56 PM
It's not that I need it shorter, it's that I wanted to ensure it was short.Calling the API yields expected results "untouched".

Darryl
03-16-2010, 02:31 PM
The problem is caused by the fact the API call that is used is "GetShortPathName" which requires that the file exist at the location in order to get its short path name. I'm assuming in your test it did not, and I have confirmed that it does work in both cases if it exists.

The problems on our end that will be fixed were that we were not returning an empty string on failure and the help did not reflect this information. These will be updated.

RizlaUK
03-16-2010, 03:46 PM
and I have confirmed that it does work in both cases if it exists.

me too, i dident test it before now, i just took it for granted it dident work (that will teach me)

Josh, i just tried the below code, with a file that does exist


sLong="C:\\Users\\Dean\\Documents\\Battlefield Heroes\\PersistentStorage.dat"
sShort=File.GetShortName(sLong);
Debug.Print(sShort.."\r\n");
Debug.Print(File.GetShortName(sShort).."\r\n");

and the result was

C:\Users\Dean\DOCUME~1\BATTLE~1\PERSIS~1.DAT
C:\Users\Dean\DOCUME~1\BATTLE~1\PERSIS~1.DAT

so in my test it returns exactly the same as the API call

C:\Users\Dean\DOCUME~1\BATTLE~1\PERSIS~1.DAT
C:\Users\Dean\DOCUME~1\BATTLE~1\PERSIS~1.DAT

and if its a file that does not exist, then its garbage like you said (maybe junk from the memory buffer), the API call tho returns a blank string