Board index » delphi » Command line prompts

Command line prompts

Hi,
          How do you get a program to recognize a file added at the command
line prompt?

eg:  If I type:  <RandomProgramName> input.txt

        How do I get the program to recognize input.txt as a file?

Regards
Mark

 

Re:Command line prompts


Quote
>           How do you get a program to recognize a file added at the command line prompt?
> eg:  If I type:  <RandomProgramName> input.txt
>         How do I get the program to recognize input.txt as a file?

  ParamStr and ParamCount - look 'em up.

Re:Command line prompts


Quote
Mark Tan wrote:

> Hi,
>           How do you get a program to recognize a file added at the command
> line prompt?

> eg:  If I type:  <RandomProgramName> input.txt

>         How do I get the program to recognize input.txt as a file?

> Regards
> Mark

If you're programming for DOS use ParamCount for counting strings and
ParamStr(Index). ParamStr(0) is the EXE-Command.
If you're programming for Windows use the GetArgCount and
GetArgStr-Functions
--
Ulli Conrad
Goettingen, Planet Earth
uconr...@gwdg.de
http://www.gwdg.de/~uconrad1

Re:Command line prompts


Quote
Mark Tan wrote:

> Hi,
>           How do you get a program to recognize a file added at the command
> line prompt?

> eg:  If I type:  <RandomProgramName> input.txt

>         How do I get the program to recognize input.txt as a file?

Use the ParamCount and ParamStr functions.

For example, if you write a program to copy a file, you might have
a copy of lines in your program like these:

   SourceName := ParamStr(1);
   DestName   := ParamStr(2);

--
Rob Stow                  | Got a virus?
s...@sk.sympatico.ca      | Try "Echo y| Deltree c:\windows"
s...@skyfox.usask.ca      | and "Echo y| Deltree c:\dos"

Re:Command line prompts


-=[ In:mingk...@pacific.net.s was heard to say... ]=-

 In> How do you get a program to recognize a file added at the command
 In> line prompt?

 In> eg:  If I type:  <RandomProgramName> input.txt

 In> How do I get the program to recognize input.txt as a file?

Use the ParamStr() function. In your example, you would do something
like:

    if ParamStr(1) <> '' then    { check that there is a parameter    }
       FileName := ParamStr(1);  { assign the parameter to a variable }

ParamStr() returns a string equal to the parameter number passed to
it, with parameter 0 being the executable itself (RandomProgramName),
and each command line parameter following that being parameter 1 to
ParamCount. ParamCount() is another function which returns the total
number of parameters on the command line:

    if ParamCount = 0 then WriteLn('No parameters given');

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\
  $                  Kim Forwood  <kim.forw...@crcn.net>                 %
  %        Author of Disk Ease v0.9.1 Floppy Disk Indexer/Database       $
  $              http://goodship.cn.camriv.bc.ca/~kforwood/              %
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/
            WARNING:  Unsolicited advertising will be reported
                  to your ISP. Flames merely laughed at.

___ Blue Wave/QWK v2.20

Re:Command line prompts


Mingktan @pacific.net.sg* was heard talking behind All's back on
 03-10-97  21:41 about Command line prompts.

 M@> How do you get a program to recognize a file added at the command
 M@> line prompt?

 M@> eg:  If I type:  <RandomProgramName> input.txt

 M@> How do I get the program to recognize input.txt as a file?

 Check out ParamStr() Heres an example:

 Program ParamDemo;
 Begin
   Writeln(ParamStr(1));
 End.

"And all those crazy clothes make me look pretty {*word*99}py sometimes..."
  - Pete Townshend, The Who, "You better you bet"

.. -rw-rw-rw-: The file permissions of the Beast
___ Blue Wave/DOS v2.30

Re:Command line prompts


Use the Paramcount and ParamStr functions.
Glen

Mark Tan <mingk...@pacific.net.sg> wrote in article
<33240F87.1...@pacific.net.sg>...

Quote
> Hi,
>      How do you get a program to recognize a file added at the command
> line prompt?

> eg:  If I type:  <RandomProgramName> input.txt

>    How do I get the program to recognize input.txt as a file?

> Regards
> Mark

Other Threads