ParamStr and ParamCount?

I'm using this code in my application to check if there are any parameters on the commandline, and if there are any, then open the files.

  if Paramcount > 0 then
      for i := 1 to Paramcount do OpenFile(ParamStr(i));

If I pass a file to my application, f.x
hahaha.txt or something, I always get
HAHA~1.TXT or something like this.
Is this ParamStr function some old crap from Win3.1?
Is there a better way do to this?
LVL 3
hagurAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hagurAuthor Commented:
Edited text of question.
0
sandman_brCommented:
Try passing the filename between parentheses. If you are using APP.EXE C:\BIGFILENAME.TXT, try APP.EXE "C:\BIGFILENAME.TXT" and see what happens.
0
intheCommented:
When you are putting a file name in an argument as a param, you have to deal with spaces.  Otherwise 'C:\My Documents' will be treated as 'C:\My' and 'Documents' (two seperate arguments).
 
There are a couple of ways to deal with this.  One is to wrap each argument with double quotes as sandman br said like  ("C:\My Documents").  The other way is to grab the ShortFileName equivalent via GetShortPathName() api or even could do it via findfirst functions:
for i:= 0 to ParamCount do
begin
  if FindFirst( ParamStr( i), faAnyFile, SearchRec) = 0 then
    Memo1.Lines.Add( ExtractFilePath( ParamStr( i)) + SearchRec.Name; { = The LongFileName}
  FindClose( SearchRec);
end;  
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

hubdogCommented:
paramstr has a bug(i think)
it can not process the param include space like inthe have said.

I solve this problem by use getcommandline api to get the whole paramstr,and use  string handle routines to process it by myself.


regards,hubdog
0
hagurAuthor Commented:
Thanks for your comments guys.

Inthe: You findfirst example works well for me.  Post your comment as an answer.
0
intheCommented:
cheers :-)

for i:= 0 to ParamCount do
begin
  if FindFirst( ParamStr( i), faAnyFile, SearchRec) = 0 then
    Memo1.Lines.Add( ExtractFilePath( ParamStr( i)) + SearchRec.Name; { = The LongFileName}
  FindClose( SearchRec);
end;  

Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.