Re: Copy File Won't Work
- From: Jan Bucek <bucek.jan@xxxxxxx>
- Date: Thu, 13 Dec 2007 22:36:18 +0100
For rename too?
DECLARE INTEGER CopyFile IN KERNEL32 STRING @lpExistingFileName, STRING @lpNewFileName, INTEGER
lcSrc=" _ test.txt" && it must exist of course
lcDst1=" _ out1.txt"
lcDst2=" _ out2.txt"
lcDst3="OK_out3.txt"
lcDst4="OK_out4.txt"
* 1. copy SRC to DEST1
? CopyFile(@lcSrc, @lcDst1, 0)
* ? CopyFile(@lcSrc, @lcDst1, 1) && fail if destination file exist
* 2. copy SRC to DEST2
FSO = CreateObject('Scripting.FileSystemObject')
FSO.CopyFile(lcSrc, lcDst2)
* 3. rename
DECLARE INTEGER MoveFile IN kernel32 STRING lpExistingFileName, STRING lpNewFileName
? MoveFile(lcDst2, lcDst4)
MikeA napsal(a):
Hello - I discovered a problem in both VFP 6 and VFP 9 where copy file fails and I'm not sure how to get around it. It seems to fail when there are spaces before the filename. Suppose you have a file in any directory called test.txt (let's say the c:\junk folder as an example). Try this:.
1. Click Start, Run and type CMD and click OK and then type CD\JUNK
2. Type Rename test.txt " test.txt"
this puts spaces before the filename which you cannot do from windows explorer but you can do at the command prompt.
3. Go into VFP and from the command prompt type the following:
m.lcFile = "c:\junk\test.txt"
? file(m.lcFile) && returns TRUE
m.lcFile2 = "c:\junk\test2.txt"
copy file (m.lcFile) to (m.lcFile2) && GIVES AN ERROR CANNOT CREATE FILE
Most likely no one would have a space or two before a filename but one of my clients did and that is how I discovered this. Is there a way to fix this? Continuing on with this crazy logic:
? file(m.lcFile) && Returns TRUE
rename (m.lcFile) to (m.lcFile2) && returns File Does Not Exist
Mike
- References:
- Copy File Won't Work
- From: MikeA
- Copy File Won't Work
- Prev by Date: Re: arrrggghhh!! Select statements..
- Next by Date: Re: arrrggghhh!! Select statements..
- Previous by thread: Re: Copy File Won't Work
- Next by thread: Any Web Servers for Visual FoxPro
- Index(es):
Loading