• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

help making a windows script/batch file

Tez

Graduate Poster
Joined
Nov 29, 2001
Messages
1,104
I need to convert a whole bunch of postscript files to pdf.

I have the program ps2pdf14 that comes with ghostscript.

If I copy a ps file into the directory this program is in, then I can do the conversion from a dos prompt by typing

"ps2pdf14 FILENAME.ps". It makes a new file FILENAME.pdf in the same directory.

Despite the specific ghostscript directory being in my path, I cant do this from any other directory, but I dont care, I'm prepared to copy all the ps files into there and then copy them out again.

The problem is that the command won't accept something like "ps2pdf14 *.ps" or "ps2pdf A.ps" or similar, and I sure dont want to go through typing in several hundred filenames!

So how to I write a script to do that for me? I used to be able to do such things on unix when I was young, but I really cant work it out on windows.

(The reason I want this is that I'm trialling a program called dtsearch, which indexes all the scientific papers I have on the hard drive and makes it trivial to search them. Works brilliantly on the pdfs but won't work on ps yet...)

Thanks for the help.
 
Here's a start, anyway.

From the directory type dir > file.txt

This will put the directory into a text file, which you can load into a word processor & manipulate.

Using the replace funtion should allow you to set up a huge part of the file pretty quickly.
 
Unfortunately, batch files can't solve the problem. But you can use good old QBasic:
Code:
SHELL "dir *.ps /b>allps.txt"
a = FREEFILE
OPEN "allps.txt" FOR INPUT AS #a
b = FREEFILE
OPEN "convert.bat" FOR OUTPUT AS #b
DO UNTIL EOF(a)
LINE INPUT #a, a$
PRINT #b, "ps2pdf14 " + CHR$(34) + a$ + CHR$(34)
LOOP
CLOSE #b
CLOSE #a
This should produce a batch file called CONVERT.BAT that you can start to convert all files in one go. Please note that I could not test this program as it depends on your exact configuration. I am fairly sure it will work, but you may need to edit it a bit.

If you have Win9x you can find QBASIC on your Windows CD. Otherwise you can download it here.
 
Earthborn it almost worked - it created the allps.txt fine, and converted the first one in the list but just not the rest...
 
That's strange... The convert BAT did contain all the names of the files, right? With 'ps2pdf14' in front of them and between quotation marks?

The only thing I can think of is that the commandline tool you use is actually a Win32 program and starts in the Windows background and the batch file just runs completely to the end with ps2pdf refusing to start again while it is converting.

If you use Win9x, it should be possible to change the PRINT command in the program to this:
PRINT #b,"start -w ps2pdf14 "+CHR$(34)+a$+CHR$(34)

That should make the batch file wait for ps2pdf to finish before it goes to the next line. I'm not sure it will work in WinNT/2000/XP...
 
FOR /R C:\pathtoyourfolder\ %%G IN (*.ps) DO ps2pdf14 %%G

That might work. I'm no Windows batch file guy but I found that with a little poking around with our friend google. Of course pathtoyourfolder will have to be changed to reflect the actual path to your folder. :)

Good Luck

Link to info I found.
 
Right. I guess no need to run it recursively is there?

Just change to the right folder and run the FOR command the way wudang described. You only need a two line batch file.
 
jimlintott said:
FOR /R C:\pathtoyourfolder\ %%G IN (*.ps) DO ps2pdf14 %%G

That might work. I'm no Windows batch file guy but I found that with a little poking around with our friend google. Of course pathtoyourfolder will have to be changed to reflect the actual path to your folder. :)

Good Luck

Link to info I found.

Earthborn, yep - the batch file contained exactly what you siad - but for some reason its only running the first line.

Tried Jim's line - and got a weird error that simply says "C:\blahblah\ was unexpected at this time" where blahblah is the path I was trying to put in.
 
Wudang said:
I think just

FOR %N in (*.PS) DO ps2pdf14 %N

will do.

Brilliant, that worked.

Thanks heaps everyone, you've made one little physics nerd very happy...
 

Back
Top Bottom