Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a program to copy itsef

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
523
Brasil
Hello dear colleagues!

I have a procedure inside MENU0REC.EXE to copy all files in the current forder to an external drive.

I am simplifying the command here:
Code:
COPY FILE C:\DEPOSITO\THAWTE\*.* TO G:

Problem is:
MENU0REC.EXE is inside C:\DEPOSITO\THAWTE folder and must also be copied to G:\, and error appears when executing the procedure inside MENU0REC.EXE.
Is it possible to circunvent this problem?



Thank you,
SitesMasstec
 
Hi SitesMasstec,
why do you use your own exe? All you need to do is a

Code:
RUN /N xcopy.exe /s/e/y C:\DEPOSITO\THAWTE G:

even better may be to call a .bat file with this line that has a little wait at startup

Code:
timeout 5 > NUL
xcopy.exe /s/e/y C:\DEPOSITO\THAWTE G:\

That should be long enough to exit your own app.

You could even create a RunOnce scheduled task with XCOPY or if you like ROBOCOPY do it with that tool.

JM2C

-Tom
 
You get error 3 - file already in use,

but an EXE can copy itself via [tt]STRTOFILE(FILETOSTR(Sys(16)),"G:\"+justfname(sys(16)))[/tt]

Now that only copies the EXE, you can't create multiple files with one STRTOFILE() call. And it's not possible to tell COPY FILE to copy all files except the EXE to do the rest with it. Also likely you can't copy foxuser.dbf, any file currently used by your EXE, so you'd have to change your strategy.

Not needing a batch file or shell command will have the advantage to not show an extra Window, so I think it's worth the effort. A way to copy with the help of STRTOFILE() would be going through all files via ADIR().

Also notice, even if COPY FILE would have worked, you don't get subfolders copied this way. You need a better copy mechanism anyway.

For your EXE to work from the external drive, you also need runtimes and if you're using OCXes that will fail on any other computer not having them installed already.
But you could do something like a portable application capable to backup itself fully including itself. without any helper files or shell commands.

Bye, Olaf.

Olaf Doschke Software Engineering
 

Hello dear colleagues!

I opted to create another .EXE file (BACKUREC.EXE, called from the main program MENU0REC.EXE, using command RUN "BACKUREC").

The BACKUREC.EXE files copies all the files I need to the pendrive (G:\ or other location), including MENU0REC.EXE. The external drive is for he backup purposes only.

Sub-folders are ok (using COPY FILE...)


Thank you,
SitesMasstec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top