Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Executing a program to copy itsef

Executing a program to copy itsef

Executing a program to copy itsef

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 -->


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,

RE: Executing a program to copy itsef

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


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


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.



RE: Executing a program to copy itsef

You get error 3 - file already in use,

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

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

RE: Executing a program to copy itsef


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,

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close