Solved

Accessing DOS commands in DELPHI 3

Posted on 1998-09-13
11
516 Views
Last Modified: 2012-06-21
In Delphi 3...how would I perform an XCOPY?

For example how would I do the following:

c:\> xcopy32 c:\source\*.*  g:\dest /e /q

I have been able to find little to no help on DOS COMMANDS in Delphi 3.  There must be a way to do this.

Thanks,

Tom
0
Comment
Question by:knowlton
11 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1339602
knowIton,

do you want to execute the dos xcopy program? Then just use winAPI ShellExecuteEx(...) or CreateProcess(...). There's no complete winAPI that does something like xcopy.
But you could several APIs to program it (FindFirstFile, CopyFile, CreateDirectory, ...).

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339603
Use this.....
             param1 : String;
             paramExt : String;
         begin
           if ParamCount >= 1 then
             begin
               param1 := UpperCase(ParamStr(1));
               paramExt := ExtractFileExt(param1);
             end;
           if (ParamCount < 1) or
              (ParamCount > 2) or
              ((ParamCount = 2) and (UpperCase(ParamStr(2)) <> '/E'))
//do something
Take this as an example......            
Use ParamStr()
and
ParamCount
to take input from DOS

if Pos('\e', PramStr(1)) then
//do something

Regards,
Viktor Ivanov
0
 
LVL 5

Author Comment

by:knowlton
ID: 1339604
Viktor:

I'm not looking to handle command-line parameters....I want to execute ACTUAL DOS commands after my program has started.

Madshi:

I think you're on the right track...but I need a complete example...one I can drop in my code and use right away.

Thanks!

Tom
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 10

Accepted Solution

by:
viktornet earned 20 total points
ID: 1339605
Here is some code.....
------------
var
  SI : TStartUpInfo;
  PI : TProcessInformation;
begin
  FillChar(SI, sizeof(SI), 0);
  SI.cb := sizeof(SI);
  CreateProcess(nil, 'C:\windows\command\xcopy32 c:\source\*.*  g:\dest /e /q ',
    nil, nil, False, 0, nil, nil, SI, PI);
end;
------------
Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339606
do you want to write an algorithm in delphi doing the same as xcopy (2nd part of madshi's) or start your app, execute a dos box running xcopy32 parametrized as shown above, and return to your app (if the latter, return immediately or wait for execute?) ?

Black Death.
0
 
LVL 5

Author Comment

by:knowlton
ID: 1339607
Viktornet:

Your reply was exactly what I was looking for.

Thanks!

BlackDeath - Yeah, I wanted a DOS box type fix...executed from within DELPHI.

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339608
No problem ;->

Try this code :-)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var
  pt : TPoint;
begin
  pt := Point($746B6956, $726F);
  Caption := PChar(@pt);
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
 
LVL 5

Author Comment

by:knowlton
ID: 1339609
Viktor:

It says "Viktor" in the caption.

Can you explain this to me?

I know that if you change the numbers like this:

From:
pt := Point($746B6956, $726F);

To:
 pt := Point($746B6957, $726F);
                                ^

It says "Wiktor" instead of "Viktor" ....so you're passing in hexadecimal values that translate into a string?

Anyway....it was cute.

Later,

Tom

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339610
John(erajoj) showed me how to write those leters...

Yes these are hexadecimal values and the first letter of your word is becoming last, the second is the one b4 the last, and so on....

There are a few other things that you need to do in order for it to show correctly...

Regards,
(@Viktor_Ivanov)^.Name;  ;->
0
 
LVL 5

Author Comment

by:knowlton
ID: 1339611
There are a few more things I need to do?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339612
No I was talking about the letter to show.... You need yo put the character 17 in the beginning of the string in hex that will determine the string, otherwise it won;t show correctly....

//Vik
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question