Amiguinhos,
Use as segunites funções
/////////////////////////////////////////////////////////////////////////////
//
// Thanks to Jim Gale
//
/////////////////////////////////////////////////////////////////////////////
#include "Struct.ch"
FUNCTION Sfn2Lfn(cShort)
Local cLong:=""
Local nFor, nAt
nAt :=1
cShort := Alltrim( StrTran( cShort, "/", "\" ) )
If !File( cShort ) .and. !lIsDir( cShort )
RETURN ""
Endif
If SubStr( cShort, 2, 1 ) == ":"
If Len( cShort ) < 4
RETURN cShort
Endif
cLong := SubStr( cShort, 1, 3)
nAt := 4
Endif
For nFor := nAt TO Len( cShort )
If SubStr( cShort, nFor, 1 ) == "\"
cLong += _Sfn2Lfn( SubStr( cShort, 1, nFor - 1 ) ) + "\"
Endif
Next
RETURN cLong+_Sfn2Lfn( cShort )
STATIC FUNCTION _SFN2LFN( cSpec )
Local oWin32, cBuffer, nHandle
STRUCT oWin32
MEMBER nFileAttributes AS DWORD
MEMBER nCreation AS STRING LEN 8
MEMBER nLastRead AS STRING LEN 8
MEMBER nLastWrite AS STRING LEN 8
MEMBER nSizeHight AS DWORD
MEMBER nSizeLow AS DWORD
MEMBER nReserved0 AS DWORD
MEMBER nReserved1 AS DWORD
MEMBER cFileName AS STRING LEN 260
MEMBER cAltName AS STRING LEN 14
ENDSTRUCT
cBuffer := oWin32:cBuffer
nHandle := apiFindFst( cSpec, @cBuffer )
oWin32:cBuffer := cBuffer
apiFindCls( nHandle )
RETURN Psz( oWin32:cFileName )
FUNCTION Lfn2Sfn(cDir)
Local cBuffer := Space(261)
Local nLen
nLen := GetShortPathName( cDir, @cBuffer, Len(cBuffer) )
RETURN Left(cBuffer, nLen)
STATIC FUNCTION psz( c ) ; RETURN substr( c, 1, At( Chr(0), c ) - 1 )
//----------------------------------------------------------------------------//
DLL32 Function apiFindFst( lpFilename AS LPSTR,;
@cWin32DataInfo AS LPSTR ) AS LONG ;
PASCAL FROM "FindFirstFileA" LIB "Kernel32.dll"
DLL32 Function apiFindNxt( nHandle AS LONG,;
@cWin32DataInfo AS LPSTR ) AS BOOL ;
PASCAL FROM "FindNextFileA" LIB "Kernel32.dll"
DLL32 Function apiFindCls( nHandle AS LONG) AS BOOL ;
PASCAL FROM "FindClose" LIB "Kernel32.dll"
DLL32 FUNCTION GetShortPathName( lpLongPath AS LPSTR,;
lpShortPath AS LPSTR,;
wBufferLen AS DWORD ) AS DWORD ;
PASCAL FROM "GetShortPathNameA" LIB "kernel32.dll"
DLL32 Function GetFullPathName( lpszFile AS LPSTR,;
cchPath AS DWORD,;
lpszPath AS LPSTR,;
@nFilePos AS PTR ) AS DWORD ;
PASCAL FROM "GetFullPathNameA" LIB "kernel32.dll"
Exemplo de salvamento de um caminho longo em formato curto:
REPLACE FILIAL->CAMINHO WITH Lfn2Sfn( cPath )
Recuperando o nome curto, salvo anteriormente e alongando-o:
cCAMINHO := Sfn2Lfn( FILIAL->CAMINHO )