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

Previously created .doc Word document not copying over to folder when requested 1

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
334
0
16
GB
Hello

I am having an issue with what I thought was a straight forward COPY FILE TO requirement. I previously created an automated .doc Word document (no issues there) but if I need to automatically search and copy the .doc file (if it exists) to a dedicated "Jobs" folder, I cannot get this to work.

Here is what I have so far:

Code:
mrecno=50    && Using this record number for jobs to test
mqrecno=214  && Using this record for quotes to test

* LONG QUOTE (WORD DOCUMENT) LINKED TO THE JOB

USE MYTABLE SHARED
GO mrecno	&&	I know this record exists

* THE BELOW cPath IS THE PATH WHERE ALL RELATED DOCUMENTS ARE STORED
* THESE ARE JOB SHEETS, QUOTES ETC - THAT'S ALL WORKING

cPath=SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+"-"+ ;
  LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE)

USE MYQUOTES SHARED
GO mqrecno

*  THIS QUOTE JOB NUMBER IS 12/2022 AND I KNOW IT EXISTS
*  QJOBNUMB=12
*  QJOBYEAR=2022

* mquotationdoc  && The name of the WORD document e.g. Quotation 12-2022 JEFFS COMPANY FIX A WINDOW

* FIELDS ARE:

mquotationdoc="Quotation "+LTRIM(STR(QJOBNUMB))+"-"+LTRIM(STR(QJOBYEAR))+ ;
  " "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE)

* cPathquote  && The path where the .doc is saved after being previously automatically generated

cPathquote=SYS(2003)+"\"+LTRIM(STR(QJOBYEAR))+" quotes\"+"Quotation "+LTRIM(STR(QJOBNUMB))+ ;
  "-"+LTRIM(STR(QJOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE)

IF FILE(cPathquote+"\"+mquotationdoc+'.doc')

*  I PUT A WAIT WINDOW HERE TO PROVE OR DISPROVE THE FILE EXISTS (IT DOES EXISTS)

   WAIT "File yes: "+cPathquote+"\"+mquotationdoc+'.doc' WINDOW

   COPY FILE cPathquote+"\"+mquotationdoc+'.doc' TO cPath  && [b]FILE IS NOT COPYING TO cPath from cPathquote[/b]
	
ELSE

   WAIT "File no: "+cPathquote+"\"+mquotationdoc+'.doc' WINDOW

ENDIF

I am stumped with this one, I'm sure it's just a minor amendment but I can't see it.

Any suggestions please or what I have missed?

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
I think I may have answered my own question but I'll leave it up in case anyone has a similar issue in the future.

Not sure if I needed to do this (there's always an easier way) however, I combined two variables like this:

Code:
cFileToCopy=cPathquote+"\"+mquotationdoc

And changed a command line from:

Code:
COPY FILE cPathquote+"\"+mquotationdoc TO cPath

To

Code:
COPY FILE(cFileToCopy) TO (cPath)

It now works so apologies if anyone was looking at this, matter resolved.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
It would have worked just as well like this:

[tt]COPY FILE [highlight #FCE94F]([/highlight]cPathquote+"\"+mquotationdoc+'.doc'[highlight #FCE94F])[/highlight] TO [highlight #FCE94F]([/highlight]cPath[highlight #FCE94F])[/highlight][/tt]

The point is that, without the parens, it would have looked for a file whose actual name was cPathquote, etc. and a distination whose actual name was cPath. The parens convert those strings to so-called name expressions, in which the contents of the parens are evaluated and then used in the command.

Thanks for posting your solution, Steve. It might well be useful to others.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
One other small point:

Instead of building a path/filename like this:
[tt]
cPathquote+"\"+mquotationdoc+'.doc[/tt]

I like to use functions such as FULLPATH(), FOREPATH(), FORCEEXT(), and so on. For example:
[tt]
FULLPATH(FORCEXT('mquotationdoc', 'doc'), cPathquote)[/tt]

It's just a matter of personal preference, of course.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike Lewis said:
I like to use functions such as FULLPATH(), FOREPATH(), FORCEEXT(), and so on. For example:

FULLPATH(FORCEXT('mquotationdoc', 'doc'), cPathquote)

As always, much obliged.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
I agree with Mike on using the functions to build file paths, but disagree about it being a personal preference. Using the functions ensures the right punctuation and makes it clear what you're doing. The functions are simply better for this.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top