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

Copy PDF file into created folder but the file is not being copied over correctly 3

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
337
GB
Hello

I am trying to copy a created PDF file into it's relevant folder but I cannot get it to copy into the correct folder.

Here is what I have so far:

**********
mrecno=205 && Just to send it to a RECNO() for testing
**********

Code:
USE MYTABLE SHARED
GO mrecno

murn=0
murn=URN
myear=0
myear=YEAR(DATE())

IF NOT DIRECTORY(SYS(2003)+"\"+LTRIM(STR(myear))+" QUOTES\"+"Quote "+LTRIM(STR(QJOBNUMB))+ ;
  "-"+LTRIM(STR(QJOBYEAR))+" "+ALLTRIM(UPPER(JOBTITLE)))

   WAIT "Creating PDF quote folder and copying document, please wait...." WINDOW NOWAIT

   MKDIR(SYS(2003)+"\"+LTRIM(STR(myear))+" QUOTES\"+"QUOTE "+LTRIM(STR(QJOBNUMB))+ ;
     "-"+LTRIM(STR(QJOBYEAR))+" "+ALLTRIM(UPPER(JOBTITLE)))

   DO LOCFILE("foxypreviewer.App")

   REPORT FORM MYQUOTATION FOR URN=murn OBJECT TYPE 10 TO FILE SYS(2003)+"\"+LTRIM(STR(myear))+ ;
     " QUOTES\"+"QUOTE-"+LTRIM(STR(QJOBNUMB))+"-"+LTRIM(STR(QJOBYEAR))+" - "+ ;
     ALLTRIM(UPPER(JOBTITLE))+'.pdf'
	
   DO foxypreviewer.app WITH "Release"

   COPY FILE SYS(2003)+"\"+"QUOTE-"+LTRIM(STR(QJOBNUMB))+"-"+LTRIM(STR(QJOBYEAR))+" - "+ ;
     ALLTRIM(UPPER(JOBTITLE))+'.pdf' TO SYS(2003)+"\"+LTRIM(STR(myear))+" QUOTES\"+ ;
     "QUOTE-"+LTRIM(STR(QJOBNUMB))+"-"+LTRIM(STR(QJOBYEAR))+" - "+ALLTRIM(UPPER(JOBTITLE))+'.pdf'

ELSE

* I'll add this in when it's working

ENDIF

RETURN

The folder that contains the quotes is named \myprogam\2022 quotes

An example folder name would be something like \myprogram\2022 quotes\quote 25-2022 job description

Both the folder name (same as the document) and pdf are created if they don't exist but the pdf is copied to the \myprogram\2022 quotes folder and not the \myprogram\2022 quotes\quote 25-2022 job description folder

I'm sure this is staring me in the face but any guidance would be helpful.


Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Well, given that the file is being correctly created, the fault most probably lies in the COPY FILE command. Now, you've got quite a complicated bit of code there. So I suggest you simplify if by first creating two variables: one to hold the source filename and the other to hold the destination. Then plug those variables into the COPY FILE.

That way, you will be able to check that the source and the destination are what you are expecting. In other words, do something like this:

Code:
lcSource =  SYS(2003)+"\"+"QUOTE-"+LTRIM(STR(QJOBNUMB))+"-"+LTRIM(STR(QJOBYEAR))+" - "+ ;
     ALLTRIM(UPPER(JOBTITLE))+'.pdf'

WAIT WINDOW lcSource

lcDest = SYS(2003)+"\"+LTRIM(STR(myear))+" QUOTES\"+ ;
     "QUOTE-"+LTRIM(STR(QJOBNUMB))+"-"+LTRIM(STR(QJOBYEAR))+" - "+ALLTRIM(UPPER(JOBTITLE))+'.pdf'

WAIT WINDOW lcDest

COPY FILE (lcSource) TO (lcDest)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello Mike

Thank you for the post.

I ran your suggestion and found the problem.

The original was:

Code:
lcDest = SYS(2003)+"\"+LTRIM(STR(myear))+" QUOTES\"+ ;
  "QUOTE-"+LTRIM(STR(mqjobnumb))+"-"+LTRIM(STR(mqjobyear))+" - "+ALLTRIM(UPPER(mjobtitle))+'.pdf'

By removing the '.pdf'

Code:
lcDest = SYS(2003)+"\"+LTRIM(STR(myear))+" QUOTES\"+ ;
  "QUOTE "+LTRIM(STR(mqjobnumb))+"-"+LTRIM(STR(mqjobyear))+" "+ALLTRIM(UPPER(mjobtitle))

It now creates the folder (if it doesn't already exist), creates the relevant PDF and copies into the folder.

A huge thank you for your contribution as always.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Glad the problem is solved. Just want to point that the FORCEPATH() and FORCEEXT() functions can help make code like this more readable, as well as help ensure the result is properly formed.

Tamar
 
Hello Tamar

Thank you for your post. I’ve not heard of them before but I’ll check them out in the help file.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top