Page 1 of 2
Truncated Parameters
Posted: Wed Jun 11, 2003 3:27 pm
by tkruk
I know this is a long shot... but here it goes...
My program relies heavily on the parameters it gets
at startup.
So I have the exe on the desktop and I can drag files on top
and it will give me the files full path. So that works nice.
But when I drag it from within a 3rd part porgram like
Total Commander (which is my file manager). I get a truncated
parameter (like c:\pro~1\file.exe) or similar.
Normally windows is ok with that but my application is for
my web server. So I need to pass the full correct path to it.
I was wondering if there is an API call or something that I
can do to "clean up" this truncated parameter into a full
one???
Any help, tips, suggestions... greatly appreciated!!!
Thank You
Tom.
Posted: Wed Jun 11, 2003 4:53 pm
by GedB
Code: Select all
shortfile$ = ProgramParameter()
;Converted from a VB example by:
;KPD-Team 2000
;URL: http://www.allapi.net/
;E-Mail: KPDTeam@Allapi.net
;create a buffer
Buffer$ = Space(255)
;copy the current directory to the buffer and append ;myfile.ext;
Ret = GetFullPathName_(shortfile$, 255, Buffer$, "")
;remove the unnecessary chr$(0);s
Buffer$ = Left(Buffer$, Ret)
;show the result
MessageRequester("", Buffer$, #PB_messagerequester_ok)
Posted: Wed Jun 11, 2003 7:02 pm
by tkruk
Copied it exactly
and it still only shows truncated version

Posted: Wed Jun 11, 2003 9:40 pm
by GPI
Try this:
Code: Select all
Procedure.s ExpandShortName(shortfile$)
i=0
b$=".";StringField(shortfile$,i,"\")
Repeat
If LongFile$
LongFile$+"\"+b$
Else
LongFile$=b$
EndIf
Repeat
i+1
a$=StringField(shortfile$,i,"\")
If Right(a$,1)=":"
LongFile$=a$
EndIf
Until Right(a$,1)<>":"
If a$<>""
If ExamineDirectory(1,LongFile$,a$)
lasttype=NextDirectoryEntry()
b$=DirectoryEntryName()
Else
break=#true
EndIf
Else
break=#true
EndIf
Until break
If lasttype=2: LongFile$+"\" :EndIf
If Left(LongFile$,2)=".\": LongFile$=Mid(LongFile$,3,Len(LongFile$)-2) : EndIf
ProcedureReturn LongFile$
EndProcedure
Debug ExpandShortName("defini~1\pureba~1.txt") ; Return "Definitions\PureBasic.TXT"
Debug ExpandShortName("f:\altern~1\defini~1\pureba~1.txt") ; Return "f:\alternate rich\Definitions\PureBasic.txt"
Debug ExpandShortName("f:\altern~1\defini~1") ; return "f:\alternate rich\Definitions\"
Debug ExpandShortName("f:\altern~1\defini~1\") ; return "f:\alternate rich\Definitions\"
Posted: Wed Jun 11, 2003 10:08 pm
by tkruk
It Outputs:
.
F:
F:
F:
... I am looking at the code and thinking 8O
I don't have folders like that. Perhaps if I had folders like that it would
work. So lemme try it agian!!!
NOOO looks like its not working. Damnnnn.
Posted: Thu Jun 12, 2003 12:43 am
by GedB
tkruk,
Is this result unique to files dragged from commander, or are you getting the same results from Explorer.
Posted: Thu Jun 12, 2003 4:44 am
by tkruk
Only from Commander. :roll:
Re: Truncated Parameters
Posted: Thu Jun 12, 2003 5:38 am
by PB
> I was wondering if there is an API call or something that I
> can do to "clean up" this truncated parameter into a full one???
This sort-of works -- it returns the file itself, but not the path.
Can anyone work out how to get the full path with it?
(BTW, thanks to GPI for the structure information).
Code: Select all
short$="c:\progra~1\zzz\test.txt"
tempname.WIN32_FIND_DATA
FindFirstFile_(short$,tempname)
Debug PeekS(@tempname\cFileName[0],260)
Re: Truncated Parameters
Posted: Thu Jun 12, 2003 6:16 am
by Max.
PB wrote:> I was wondering if there is an API call or something that I
> can do to "clean up" this truncated parameter into a full one???
This sort-of works -- it returns the file itself, but not the path.
Can anyone work out how to get the full path with it?
(BTW, thanks to GPI for the structure information).
That is what Microsoft suggests, so it *looks* as if there is no API call.
http://support.microsoft.com/default.as ... bContent=1
They kinda use the VB Dir() command to build up a string with the long path by working from the root down to the file manually.
Posted: Thu Jun 12, 2003 9:04 am
by PB
> NOOO looks like its not working. Damnnnn.
GPI's example works for me with short paths on my system (I used my
own short paths, not the ones given by GPI). Thanks, GPI!

Posted: Thu Jun 12, 2003 10:34 am
by GedB
I really can't understand why the API call isn't working it should.
This is what the Win32 help file has to say, it specifically says that the filename returned is the long version:
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
);
Parameters
lpFileName
Points to a null-terminated string that specifies a valid filename. This string can use either short (the 8.3 form) or long filenames.
nBufferLength
Specifies the size, in characters, of the buffer for the drive and path.
lpBuffer
Points to a buffer that contains the null-terminated string for the name of the drive and path.
lpFilePart
Points 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 Values
If 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.
Remarks
The 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.
Posted: Thu Jun 12, 2003 12:49 pm
by PB
> I really can't understand why the API call isn't working it should.
GPI's example works, as long as the short path leads to an actual file.
Don't know why the other VB examples don't work in PureBasic, though.
Posted: Thu Jun 12, 2003 1:23 pm
by GedB
OK, Now I've got it.
GetFullPathName() was a mistake. I though it was the complement of GetShortPathName() which converts to 8.2, but it isn't. It's only purpose is to concanate a path and a filename. It does expand from 8.2, but only for the filename and not the path.
FindFirstFile returns the filename expaned, but again doesn't touch the path. As Max and PB have pointed out you need to expand outwards from the root.
So here is a rewrite GPI's example using API calls.
Code: Select all
paramfile$ = ProgramParameter()
Procedure.s ExpandShortPath(ShortPath$)
FieldNumber.l = 1
FindData.WIN32_FIND_DATA
LongPath$ = StringField(ShortPath$, FieldNumber, "\")
Repeat
FieldNumber = FieldNumber + 1
field$ = StringField(ShortPath$, FieldNumber, "\")
If field$ <> ""
FindFirstFile_(LongPath$ + "\" + field$,@FindData)
field$ = PeekS(@FindData\cFileName[0])
LongPath$ = LongPath$ + "\" + field$
Debug LongPath$
EndIf
Until field$ = ""
ProcedureReturn LongPath$
EndProcedure
Buffer$ = Space(255)
ResultLength = GetShortPathName_(paramfile$, @Buffer$, 255)
ShortFile$ = Left(Buffer$, ResultLength)
LongFile$ = ExpandShortPath(ShortFile$)
MessageRequester(ShortFile$ + "(" + paramfile$ + ")", LongFile$, #PB_messagerequester_ok)
Testing is sometimes spoilt because on most version of explorer the full path is passed, so I've added a call to GetShortPathName to make sure its working.
TKruk, please, please tell me this works before I lose all my hair.
Posted: Thu Jun 12, 2003 2:28 pm
by tkruk
GedB: THANK YOU... IT WORKS IT WORKS IT WORKS...
Whooo. (catching my breath)... I just want to say one thing.
This community is great. I can not believe the wonderful response from
all of you. This is a shock. But I'm an "old" Amiga user (I'm 28 BTW)...
So I this reminds me of the Amiga Cult following...
These newsgroups are great, and there's tons of good info here.
You guys know what. We should publish a newsletter here with like
the best tips and tricks and solutions to problems, and examples, and
articles.... It would be so great. I am so happy. this will save me so
much time in my work....
BTW: I am professionally employed by big company (cant say who) as a web developer. So I do graphics and code ASP, Flash, etc... I would be
happy to contribute if there was an interest... Perhaps I'll email the creator.
BUT... THANK YOU ONCE AGAIN. COULDN'T HAVE DONE IT WITHOUT YOU!
PureBasic ROCKS!
Posted: Thu Jun 12, 2003 2:46 pm
by Fred