Announcement

Collapse
No announcement yet.

File.GetShortName() on already short names.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File.GetShortName() on already short names.

    See the image -- when using short names to File.GetShortName() I'm getting garbage...

  • #2
    god d.a.m man, how short do you want that path

    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
    Code:
    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));
    Embrace change in your life, you never know, it could all work out for the best

    Comment


    • #3
      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".

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Code:
          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
          Code:
          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
          Code:
          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
          Embrace change in your life, you never know, it could all work out for the best

          Comment

          Working...
          X