请问如何吧C:\DOCUME~1\转换成完整路径?
例如C:\DOCUME~1\应当转换成C:\Documents and Settings\
应该有哪个WIN API可以实现.请各位高手给小弟个小例子.或者知道哪个API也可以.谢谢

解决方案 »

  1.   

    听说有个API可以实现转换.我的例子就是上面的那个啊.
      

  2.   

    The GetFullPathName function retrieves the full path and filename of a specified file. DWORD GetFullPathName(    LPCTSTR lpFileName, // address of name of file to find path for 
        DWORD nBufferLength, // size, in characters, of path buffer 
        LPTSTR lpBuffer, // address of path buffer 
        LPTSTR *lpFilePart  // address of filename in path 
       );
     ParameterslpFileNamePoints to a null-terminated string that specifies a valid filename. This string can use either short (the 8.3 form) or long filenames.nBufferLengthSpecifies the size, in characters, of the buffer for the drive and path. lpBufferPoints to a buffer that contains the null-terminated string for the name of the drive and path. lpFilePartPoints to a variable that receives the address (in lpBuffer) of the final filename component in the path. This filename component is the long filename, if any, rather than the 8.3 form of the filename. Return ValuesIf the GetFullPathName function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. 
    If the lpBuffer buffer is too small, the return value is the size of the buffer, in characters, required to hold the path. 
    If the function fails, the return value is zero. To get extended error information, call GetLastError. ResThe GetFullPathName function merges the name of the current drive and directory with the specified filename to determine the full path and filename of the specified file. It also calculates the address of the filename portion of the full path and filename. This function does not verify that the resulting path and filename are valid or that they refer to an existing file on the associated volume.
      

  3.   

    uses ShlObj,Comobj,ActiveX;function ShortToLongFileName(const ShortName: string): string;
    var
      Desktop: IShellFolder;
      pIDList: PITEMIDLIST;
      NameS: String;
      NameW: WideString;
      Len : integer;
      Buffer: array[0..MAX_PATH] of Char;
      pDummy: PCHAR;
      pchEaten, Attributes: ULONG;
    begin
      pIDList := Nil;
      Len := GetFullPathName(PChar(ShortName), 0, PChar(result), pDummy);
      SetLength(NameS, Len);
      GetFullPathName(PChar(ShortName), Len, PChar(NameS), pDummy);
      NameW := NameS;
      OleCheck(SHGetDesktopFolder(Desktop));
      OleCheck(Desktop.ParseDisplayName(0, Nil, PWideChar(NameW), pchEaten, pIDList, Attributes));
      if not SHGetPathFromIDList(pIDList, Buffer) then
      raise EConvertError.Create('error');
      Result := StrPas(Buffer);
    end;
      

  4.   

    uses
      ShellAPI;
    ...
    function GetLongFileName(const FileName: string): string; 
    var 
      SHFileInfo: TSHFileInfo; 
    begin 
      if SHGetFileInfo(PChar(FileName),
                       0, 
                       SHFileInfo,
                       SizeOf(SHFileInfo), 
                       SHGFI_DISPLAYNAME) <> 0 then 
        Result := string(SHFileInfo.szDisplayName)
      else 
        Result := FileName; 
    end;
      

  5.   

    #include <Winbase.h> // BCB Code
    void __fastcall TForm1::Button5Click(TObject *Sender)
    {
        static char strLongName[MAX_PATH+4];
        GetLongPathName ( "C:\Progra~1", strLongName, MAX_PATH );
        ShowMessage ( strLongName );
    }
      

  6.   

    同志们.拿到DELPHI就没有能实现这个功能的嘛?想给分都不行.非让散分啊.
      

  7.   

    GetLongPathName 是 API 来的呀,在 Delphi 是可以的吧
    我现在没有安装 Delphi,回家帮你看看
    看看 MSDN 中的帮助
    GetLongPathName
    [This is preliminary documentation and subject to change.] The GetLongPathName function converts the specified path to its long form. If no long path is found, this function simply returns the specified name. DWORD GetLongPathName(
      LPCTSTR lpszShortPath, 
      LPTSTR lpszLongPath, 
      DWORD cchBuffer
    );
     
    Parameters
    lpszShortPath 
    Pointer to a null-terminated path to be converted. 
    lpszLongPath 
    Pointer to the buffer to receive the long path. You can use the same buffer you used for the lpszShortPath parameter. 
    cchBuffer 
    Specifies the size of the buffer, in characters. 
    Return Values
    If the function succeeds, the return value is the length of the string copied to the lpszLongPath parameter, in characters. This length does not include the terminating null character.If lpszLongPath is too small, the function returns the size of the buffer required to hold the long path, in characters.If the function fails, the return value is zero. To get extended error information, call GetLastError.QuickInfo
      Windows NT: Requires version 5.0 or later.
      Windows: Requires Windows 98 or later.
      Windows CE: Unsupported.
      Header: Declared in winbase.h.
      Import Library: Use kernel32.lib.
      Unicode: Implemented as Unicode and ANSI versions on Windows NT.See Also
    File I/O Overview, File Functions, GetShortPathName
      

  8.   

    Mark! 这应该不是 Delphi 的问题,看看有没有相关的 api
      

  9.   

    我觉得应该是 GetFullPathName 的,不过我在 Delphi 中不会使用这个函数^_^ 怎么定义二维数组?
      

  10.   

    我觉得应该是 GetFullPathName 的,不过我在 Delphi 中不会使用这个函数^_^ 怎么定义二维数组?
      

  11.   

    测试了一下,GetFullPathName 函数达不到目的