GetShortName/GetLongName

2 views
Skip to first unread message

Why Tea

unread,
Dec 28, 2009, 2:58:06 AM12/28/09
to SemWare
Given a file name in short format, is there a way to get the long file
name via Windows dll? And the opposite?

/Why Tea

S.E. Mitchell

unread,
Dec 28, 2009, 8:59:08 AM12/28/09
to sem...@googlegroups.com
The following example assumes that you have a file called
'associations.doc' in the current directory:

dll "<kernel32.dll>"
integer proc GetShortPathName(string inpath:cstrval, var string
outpath:strptr, integer len) : "GetShortPathNameA"
end

/**************************************************************************
GetShortPathName only works for existing path's..., so create inpath if
it does not already exist.
**************************************************************************/
string proc mGetShortPathname(string inpath)
integer h, len
string short_path[_MAX_PATH_] = Format("":_MAX_PATH_:Chr(0))

h = iif(FileExists(inpath), -1, fCreate(inpath))
len = GetShortPathName(inpath, short_path, _MAX_PATH_)
if h <> -1
fClose(h)
EraseDiskFile(inpath)
endif
return (iif(len > 0, short_path[1:Pos(Chr(0), short_path) - 1], inpath))
end

string proc mGetLongPathname(string inpath)
return (ExpandPath(inpath))
end

<f3> Warn(mGetShortPathname("associations.doc"))
<f4> Warn(mGetLongPathname("associ~1.doc"))

Why Tea

unread,
Dec 28, 2009, 7:42:35 PM12/28/09
to SemWare
Thanks Sammy. /Why Tea
Reply all
Reply to author
Forward
0 new messages