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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COPY FILE in an Exe

Steve Meyerson

Programmer
Sep 17, 2020
331
US
I created a backup method using COPY FILE within the main form (Stock.scx/sct) of the project.

It will not copy Stock.scx because it is open of course.

But when I build the exe, close the project, quit VFP, and run the exe, it copies other files, but still will not copy Stock.scx. Msg: "File in Use"

Everything's in the same folder but I would think running the backup in the exe should copy the scx anyway because Stock.scx is on the hard drive, but NOT open.

What am I not seeing? Anyone?

Steve
 
Yes. I even checked Process & Services in the Task Manager for "Stocks.." or "MicrosoftVisua..". Nothing.

I even copy/pasted Stocks.scx to my backup folder while the exe was running. It copied ok. So that indicates it was not open.

I put it in a TRY/CATCH/ENDTRY. Still wouldnt copy but at least no message,
 
Igor,

.scx is the extension of a form's file name. It's normally accompanied by a .sct file which has the same stem of the form's file name, but having .sct as its extension. I think the .sct file is like a 'memo' file. Both are really same structure as dbf/dbt files.

Clear? (as mud?:confused:)
 
I think it is because within the EXE the stock.scx will be referring to the running scx that's within the EXE.

I tried a reproduction of the problem and succeeded.
In a main.scx form I put a button that has this in its click:
Code:
Copy File another.scx To backup\another.scx
Copy File another.sct To backup\another.sct
Copy File some.scx to backup\some.scx
Copy File some.sct to backup\some.sct
Copy File main.scx to backup\main.scx
Copy File main.sct to backup\main.sct

Well, and as you can guess from that code I also have some.scx and another.scx in the project:
1750450713792.png
As you can see another.scx is excluded from the exe building, some.scx is included and main.scx is the main form. I made it modal, too and have no main.prg, for having these three different things.

After building, closing VFP and running the EXE I ge the same error for main.scx - "File is Open" in the line that copies the main.scx

And then I saw this in the folder:
1750450697326.png
It turns out that's still neither a new VFP bug nor a new Windows feature hindering VFP from working, it is due to a cloud storage I use with a sync feature for the whole tek-tips directory.

Anyway, I can also get the same error (FIle is open error, not the conflicted in the file name) when I wait for the sync to have finished and it's due to VFP referring to the main.scx within the EXE as it's searched and found first there.

As continuation of the experiment I did change some.scx and another.scx to have a label - the original scxes were just empty forms. I now did not rebuild the exe, so it's internal some.scx is still empty, the external some.scx has a label. there is no internal another.scx, only the external one. Now restarting the exe I still get the same error - didn't expect anything else.

But looking into the backup folder I see another.scx has the new label in it - it was overwritten from the changed original file. The some.scx that's included in the EXE without label can be found in the backup unchanged, so the internal some.scx is copied. The external some.scx was not copied over. Actually the some.scx and sct also were overwritten (safety messages popped up, whether I want to overwrite and I confirmed all 4 of them with yes). But the some.scx/sct were overwritten with the same old unlabeled some.scx form the files that still exist in the EXE as I didn't rebuilt it, the changed some.scx ws not copied.

So, in short: When using COPY FILE you don't necessarily copy files as found on disk, you also - and with priority if found inside the EXE - copy files from within the EXE.

I remembered this did not effect all file related commands and thought only FILETOSTR() could read from inside the exe, besides image files I told about in a not so recent thread are also taken from inside an exe from image controls picture properties. Anyway, it's obviously also effecting COPY FILE.

So to not copy from within your backup tool EXE you either use Windows API functions like MoveFileEx instead of VFPs COPY FILE or you ensure whatever you want to copy has no name as can also be found in your EXE.
 
Last edited:
When using COPY FILE you don't necessarily copy files as found on disk, you also - and with priority if found inside the EXE - copy files from within the EXE.,

That explains it! I guess the file itself is actually inside the exe (or at least VFP treats it as such).

The example you created duplicates nearly exactly what I actually have, i.e. I have another scx (not the Main) which is not active during backup. It copies fine in the exe. I suppose if it were active it would also not copy.

I guess I had not run into this before. In any case, I don't distribute this app so I can back up the file manually or rely on my Acronis timed (once a day) backup. I figured it was just more convenient to do it in one click in my program.

Thanks Chris for your help. And also for your insight and expertise!

Steve
 
SCX and SCT-Files are actually same like a DBF and its FPT.
You can access those FORM-Files like any table
Code:
USE Stock.SCX alias CopyStock in 0 shared again
COPY TO <YourDestination>.SCX
USE IN SELECT CopyStock
 
Ein,

Tried it in exe with all else closed. First line gives "File is in use." message.

Just realized you were probably addressing Igors post.

Steve
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top