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

COPY FILE 1

Status
Not open for further replies.

psperry2

Programmer
Nov 7, 2007
141
US
This command works:

COPY FILE "c:\temp\_2iz0i7glg.txt" TO "G:\FOXPROJ\Philip\WorkArea_HumanResources\HumanResources\internal_auditing_data\trash_20081204082920.txt"

however the file names are stored in variables and I can't get a foxpro command to work with these variables that actually does the copy.

I tried COPY FILE (l_cTempTextFile) TO (l_cBackupFile)
(this executes and there is no error, but the file does not get copied)

I tried COPY FILE &l_cTempTextFile TO &l_cBackupFile
(this executes and there is no error, but the file does not get copied)

Can anyone give me a command that works with these variable names that actually copies?
 

COPY FILE (l_cTempTextFile) TO (l_cBackupFile) usually works for me.
 

Well, at least one of your commands is correct.

If your command is correct and is not working, something else must be wrong.

Can you show an example of exact contents of your variables?
Did you check if your directories are not marked read-only, that the file is not in use, etc.?
Did you try to issue the commands interactively, from the command window and not in the program?
 
You also have to keep in mind that if there are any spaces in the file paths, you will need to use extra quotes around them. For instance:
Code:
STORE '"C:\Program Files\Some Folder\Oldfile.txt"' TO cSourceFile

STORE '"C:\Program Files\Some Folder\Newfile.txt"' TO cTargetFile

COPY FILE (cSourceFile) TO (cTargetFile)


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Stella the contents of l_cTempTextFile is c:\temp\_2iz0i7glg.txt and the contents of l_cBackupFile is G:\FOXPROJ\Philip\WorkArea_HumanResources\HumanResources\internal_auditing_data\trash_20081204082920.txt

The fact that in the command window the first command works shows that I have the right permissions.

The other 2 commands execute without any error yet the file does not get copied. There are no spaces in the file path Dzumm

So I am still stumped
 

This is the way it works for me - but with your file names:

Code:
l_cTempTextFile="c:\temp\_2iz0i7glg.txt"
l_cBackupFile="G:\FOXPROJ\Philip\WorkArea_HumanResources\HumanResources\internal_auditing_data\trash_20081204082920.txt"

COPY FILE (l_cTempTextFile) TO (l_cBackupFile)

Can you test this snippet?

You said, your file names are variable - surely you don't just assign them as in the test above. How do you create them? You, probably, use DTOS() function and other ways of creating your variables - can you show that code? Are you sure you variable is what you expect it to be? Did you check using the debugger if you actually created the correct path/file name?
 
I got it to work once, and it took exceptionally long. It was almost a full minute from the time I executed the command in the command window until the blinking cursor returned and then in the Windows explorer window, the file showed up.

but the original command works instantly: COPY FILE "c:\temp\_2iz0i7glg.txt" TO "G:\FOXPROJ\Philip\WorkArea_HumanResources\HumanResources\internal_auditing_data\trash_20081204082920.txt"

So why does using copy file command with variables to hold file names and using a plain copy file command vary in execution time?
 

For me, it mostly the other way around.
Here, MasterFile2008.dbf is a 94Mb file.
Code:
a=seconds()
copy file "C:\dummy\MasterFile2008.dbf" TO "C:\default\Master_copy1.dbf"
b=seconds()
aaa="C:\dummy\MasterFile2008.dbf"
bbb="C:\default\Master_copy2.dbf" 
copy file (aaa) TO (bbb)
c=seconds()
?b-a   && first run: 2.664, second run: 3.205
?c-b   && first run: 1.047, second run: 2.731

The tests above was a run a few times. The times I showed are for runs with SET TALK ON.

With SET TALK OFF, the times are not that much apart, and couple of times I did get the second example run just a bit slower than the first one, see below.

Code:
...
?b-a   && first run: 2.247, second run: 2.391
?c-b   && first run: 2.393, second run:    2.933

By the way, what's your SET TALK setting?

I got it to work once ...
Are you saying that you tried more than once and it didn't work?


Anyway, since it does work this way, then there are two major possibilities why it doesn't work in the program. Either your variables is not what you expect it to be - as I already asked you to check, or something is going on and it doesn't have enough time to copy by the time you check.

Again, turn on the debugger to check both possibilities.
Walk through that part step by step, and see what file names are evaluated to, and also how long does it take to complete the command, etc.
 
You also have to keep in mind that if there are any spaces in the file paths, you will need to use extra quotes around them.

That's not correct. When you use name expressions (parens around the variable), it takes care of the quotation mark issues.

Tamar
 
I can only repeat what others are saying, it works, and it is not making a difference doing it in code or directly in the command window, with variables or with hard coded fiel names.

What you're seeing must be outside of foxpro, maybe a malicious hard drive.

Is G: a network drive? Network traffic will make the performance vary then for example.

Bye, Olaf.
 
I don't know if this will help but I had a glitch similar to this on a program I was working with. I was using a variable database call and the syntax:
use xpricing shared
or
use &xpricing shared
wouldn't work.

When futility struck I tried
USE xpricing + '' shared
and it worked like a charm.

Good luck,


If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top