WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on December 27, 2018, 11:36:27 AM

Title: fileRename not working
Post by: MW4 on December 27, 2018, 11:36:27 AM
I am trying to use a variable pulled from a pdf, and I'm getting a file rename error 123.
I have tried many different ways and I still can't get it to save with the new filename which in my example is B12345.

Any Ideas?

Code (winbatch) Select
RosPdftxt="Y:\Data\Test\PDFS\TodaysRos.txt"

PdfData = FileGet(RosPdftxt)
TotalLines = (ItemCount(pdfdata, @LF) )
 
RosNum = ""

For InvoiceLine = 1 To TotalLines


ThisLine  = ItemExtract(InvoiceLine, pdfdata, @LF)


if strsub(ThisLine, 1, 24) == "OF MULTIPLE NEW VEHICLES"

ThatLine  = ItemExtract(InvoiceLine+1, pdfdata, @LF)
     
RosNum = strsub(ThatLine, 1, 7)
     
endif


next

message(rosnum,rosnum)


;*************************************************************
;*************************************************************


adobe = ObjectCreate("AcroExch.app")      ; create an application object
PDF = ObjectCreate("AcroExch.pdDoc")

PDFFileName = "Y:\Data\Test\PDFS\a.pdf"
t1 = PDF.open(PDFFileName)


StringSave = strcat("Y:\Data\Test\PDFS\" : rosnum : ".pdf")

;message("stringsave",stringsave)
;message("stringsave",%rosnum%)

t2 = PDF.save(1,"Y:\Data\Test\PDFS\aaa.pdf")

PDF.close

adobe.exit; exit the application

adobe = ""      ; close the application object
FirstPDF = ""      ; close the application object

filerename  ("Y:\Data\Test\PDFS\aaa.pdf"  , stringsave)


exit
Title: Re: fileRename not working
Post by: td on December 27, 2018, 12:15:04 PM
While not related to your problems, why are using both the concatenation operator and the StrCat function on the line:

StringSave = strcat("Y:\Data\Test\PDFS\" : rosnum : ".pdf") ?

You only need to use one or the other but not both.  As is you are just wasting CPU cycles.

Assuming you mean that the 123 system error,  text associated with that error is "The filename, directory name, or volume label syntax is incorrect."  You can find Win32 system error description on our Tech Support site or on Microsoft's site.

The above description is kinda self-explanatory and it isn't possible to tell you what the exact syntax error is because the value of the "RosNum" variable is not discernible without running your script with your data files.
Title: Re: fileRename not working
Post by: MW4 on December 27, 2018, 12:45:07 PM
That was just the last way I tried to make it work.

StringSave = strcat("Y:\Data\Test\PDFS\", rosnum,".pdf")

StringSave = "Y:\Data\Test\PDFS\" : rosnum : ".pdf"

StringSave = strcat("Y:\Data\Test\PDFS\" : rosnum : ".pdf")
Title: Re: fileRename not working
Post by: MW4 on December 27, 2018, 02:14:01 PM
There was a stray CRLF in there which I used a...

rosnum = StrClean (rosnum, @CRLF, "", @TRUE, 1)  to fix.

Works now
Title: Re: fileRename not working
Post by: td on December 28, 2018, 08:57:41 AM
The problem was not how you concatenated but what you concatenated. Thanks for letting us know you figured out the what the what was.