Link to home
Start Free TrialLog in
Avatar of wasabi3689
wasabi3689Flag for United States of America

asked on

how to run a batch process

I have word convert to PDF .exe program. This program can convert each single Word file to a PDF file. I have a folder with few hundred word files. instead manaully copy/paste each file one by one to generate output file. I want to run a batch process to be able to pick up all the file names from the folder, then run the .exe program and convert each Word file to PDF and output to  a location.


How to write this script?
Avatar of NVIT
NVIT
Flag of United States of America image

> ...convert each Word file to PDF and output to  a location.

It's best to do a test against several files first, to make sure it works. It's up to you.

Make file convertpdf.bat with this code:

@echo off
pushd c:\folderofpdfs
for %%a in ("*.pdf") do convertprogram.exe "%%~dpnxa" "c:\outputfolder"
popd

Open in new window


Open a CMD window

Type: convertpdf.bat
Avatar of wasabi3689

ASKER

@echo off
pushd Z:\Integration\wordToPDF-ED
for %%a in ("*.doc") do OfficeToPDF.exe "%%~dpnxa" "Z:\Integration\wordToPDF-ED"
popd

Open in new window


I have this error " UNC paths are not supported. Dafaulting to Windows directory"

Z:\Integration\wordToPDF-ED is a network drive
Here is he entire error

'\\abc\efg\Integration\wordToPDF-ED'
CMD.EXE was started with the above path as the current directory
UNC paths are not supported.  Defaulting to Windows directory.

My OfficeToPDF.exe is resided in '\\abc\efg\Integration\wordToPDF-ED'
This is Microsoft word to PDF
any ideas? help please
Just awoke. 8-)

try this:

@echo off
cd /d Z:\Integration\wordToPDF-ED
for %%a in ("*.doc") do OfficeToPDF.exe "%%~dpnxa" "Z:\Integration\wordToPDF-ED"

Open in new window

Still not working.

If I click on the .bat file as administrator, I have this error

'\\abc\def\Integration\wordToPDF-ED'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
Press any key to continue . . .


If I open a command line to execute the program like below

Z:\Integration\wordToPDF-ED>FileConversion.bat
Press any key to continue . . .

Z:\Integration\wordToPDF-ED>


There is no error message but no output file

any ideas?
- For testing, change to this. It will echo the command but not execute it. Open a command line then run the .bat. Does it look correct?
- Also, you have the input folder the same as the output folder. Is that correct?

@echo off
cd /d Z:\Integration\wordToPDF-ED
for %%a in ("*.doc") do ECHO OfficeToPDF.exe "%%~dpnxa" "Z:\Integration\wordToPDF-ED"

Open in new window

Yes I have the input folder the same as the output folder. But, later I want to change it. So far I want to make work and make it simple first.
I ran the .bat program again with ECHO. I have the following

Z:\Integration\wordToPDF-ED>FileConversion.bat
OfficeToPDF.exe "Z:\Integration\wordToPDF-ED\36b4c477-aacc-4a9a-b1ee-0c8cebb73c3
9.doc" "Z:\Integration\wordToPDF-ED"
OfficeToPDF.exe "Z:\Integration\wordToPDF-ED\efbc45c5-627f-4024-a5bc-1f8742b968a
5.doc" "Z:\Integration\wordToPDF-ED"
Press any key to continue . . .
If you do each line separately in the command window, does it work?
OfficeToPDF.exe "Z:\Integration\wordToPDF-ED\36b4c477-aacc-4a9a-b1ee-0c8cebb73c39.doc" "Z:\Integration\wordToPDF-ED"

Open in new window


I don't know what it takes to run OfficeToPDF.exe successfully, e.g. whether the target folder needs to differ or not. You'll need to confirm that.
The target folder can be different.

if do this line by line, it works

OfficeToPDF.exe "Z:\Integration\wordToPDF-ED\36b4c477-aacc-4a9a-b1ee-0c8cebb73c39.doc" "Z:\Integration\wordToPDF-ED\36b4c477-aacc-4a9a-b1ee-0c8cebb73c39.pdf"
And if you do it without the target pdf filename it doesn't, right?

OfficeToPDF.exe "Z:\Integration\wordToPDF-ED\36b4c477-aacc-4a9a-b1ee-0c8cebb73c39.doc" "Z:\Integration\wordToPDF-ED"

Doesn't work, right?
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One more thing

If the document has macro, how to also convert the macro in the each file. So far, after the conversion from Word to PDF, part of the contents are lost,  like below after open the file



Error! Reference source not found.Error! Reference source not found.
Error! Reference source not found.
DATE : Error! Reference source not found.
VISIT TYPE: Error! Reference source not found.
Error! Reference source not found. Error! Reference source not found.
Error! Reference source not found.
> ...how to also convert the macro in the each file

Your original question has been answered and solved. Please close the question accordingly.

I am not familiar with OfficeToPDF.