coerrace
asked on
batch to convert pdf to jpg command prompt
hello I want to convert pdf to jpg in a batch and I'm using the:http://www.imagemagick.org /
They way to use is simply:
Now I want to do a batch in command prompt. I have a directory called c:\data inside that directory there are a lot of sub directories each directory by the same way inside has different pdf files with different names then I want that the batch look for all sub directories inside c:\data and then look inside each sub directory for the pdf files if found convert that pdf file inside the same directory where was found and exist the pdf found and with the same name than the original pdf and on that way with all sub directories and all pdf files. Of course some of that sub directories contain a lot of pdf files another sub directories have just one pdf or two and some has other kind of formats like flv, doc or whatever and that other formats different than pdf must not be touched must be converted the pdf files only. I tried to do this batch but doesn't work:
Thank you so much
They way to use is simply:
convert file.pdf file.jpg
Now I want to do a batch in command prompt. I have a directory called c:\data inside that directory there are a lot of sub directories each directory by the same way inside has different pdf files with different names then I want that the batch look for all sub directories inside c:\data and then look inside each sub directory for the pdf files if found convert that pdf file inside the same directory where was found and exist the pdf found and with the same name than the original pdf and on that way with all sub directories and all pdf files. Of course some of that sub directories contain a lot of pdf files another sub directories have just one pdf or two and some has other kind of formats like flv, doc or whatever and that other formats different than pdf must not be touched must be converted the pdf files only. I tried to do this batch but doesn't work:
For /R C:\data %%I IN DO (.) convert "\%%I\*.pdf" "\%%I\*.jpg"
Could anyone can help me in modify the script to make work and put the code?Thank you so much
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you mean that search file and convert it to jpg file and put at the same location, right ?
Duncan
Duncan
ASKER
well if the word search apply is search but for example when you use copy *.do c:\ it grab just the .doc files to c:\ but maybe is not a kind of search but if apply the word is ok. In what I need is for each subdirectory convert only the pdf files and convert to jpg and store in same sub directory where pdf is and the rest of other extensions must be ignored and on that way for all sub directories inside c:\data
Thank you
Thank you
So just, you mean that search pdf files at c: drive and convert it to jpg files and save them at the same location they are converted from.
Duncan
Duncan
ASKER
not c: is c:\data and inside c:\data there are a lot of subdirectories the pdf "search" must be in all subdirectories inside c:\data for example search in c:\data\one in c:\data\two and so on there are hundred of sub directories there, "one" and "two" are not real could be any name in that hundred of directories inside c:\data
Thank you
Thank you
You want the mogrify command, not convert, because mogrify accepts a wildcard. This command should do it for you:
Regards, Joe
For /R C:\data %%I IN DO (.) mogrify -format jpg *.pdf
Regards, Joe
try this code, do it in example files and directory first, it will work,
@echo off
forfiles /p "c:\data" /s /m *.pdf /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt
I should have mentioned that <mogrify.exe> is in the same ImageMagick install folder as <convert.exe>, but you probably figured that out already. :) However, the one-line code I posted is wrong. I'm very sorry about that — I feel really bad. Here's code that I just tested with mogrify and it works fine:
FOR /R "d:\0tempd\test\" %%I in (.) DO (
Pushd %%I
mogrify -format jpg *.pdf
Popd )
Once again, I apologize for the previous bad code. Regards, Joe
FOR /R "d:\0tempd\test\" %%I in (.) DO (
Pushd %%I
mogrify -format jpg *.pdf
Popd )
Once again, I apologize for the previous bad code. Regards, Joe
ASKER
joe winograd I used your line and appears is bad formatted say:
do was unexpected at this time and like that if you make work sure go to search in subdirectories? Looks great I changed the IN DO (.) by IN (.) DO and does more but I see not go to inside sub directories to conver the files the error say:
mogrify: unable to open image `*.pdf': Invalid argument @ error/blob.c/OpenBlob/
2587.
And that means is looking inside c:\data but not inside the subdirectories could you check I like mogrify.
duncanb7 why you use the del command? if it is just convert? don't want to destroy any data is a server.
do was unexpected at this time and like that if you make work sure go to search in subdirectories? Looks great I changed the IN DO (.) by IN (.) DO and does more but I see not go to inside sub directories to conver the files the error say:
mogrify: unable to open image `*.pdf': Invalid argument @ error/blob.c/OpenBlob/
2587.
And that means is looking inside c:\data but not inside the subdirectories could you check I like mogrify.
duncanb7 why you use the del command? if it is just convert? don't want to destroy any data is a server.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
del command , just delete junk.txt temp file only after finishing all convert, that file
is not related to convert
I have checked the script is working I used "copy" to simulate "convert" effect
Duncan
is not related to convert
I have checked the script is working I used "copy" to simulate "convert" effect
Duncan
ASKER
Both scripts worked is just needed to run in my case in c:\ if I run from c:\temp for example not work but from c:\ all perfect.
Thank you
Thank you
> if I run from c:\temp for example not work
Hmmm, I don't understand that. I haven't tried Duncan's solution, but I can tell you that mine should work fine running from c:\temp (in my test, I used d:\0tempd\test and it worked fine). In any case, you're welcome — and I'm glad you got it working! Regards, Joe
Hmmm, I don't understand that. I haven't tried Duncan's solution, but I can tell you that mine should work fine running from c:\temp (in my test, I used d:\0tempd\test and it worked fine). In any case, you're welcome — and I'm glad you got it working! Regards, Joe
ASKER
I opened this new question just for a modification if you can help there:
http://www.experts-exchang e.com/OS/M icrosoft_O perating_S ystems/MS_ DOS/Q_2848 7736.html
Thank you
http://www.experts-exchang
Thank you
I'm leaving my office now for around 3-4 hours. I'll look at your new question as soon as I return. Regards, Joe
thx for your pt
ve a nice day
duncan
ve a nice day
duncan
ASKER
a directory called "one" and another called "two"
inside "one" there are these pdf files: 1.pdf, 2.pdf and 3.pdf and the directory "two" has these pdf files other1.pdf and other2.pdf
These 2 directories are inside c:\data and the batch must convert for example when pass to directory "one" convert the files 1.pdf, 2.pdf and 3.pdf to 1.jpg, 2.jpg and 3.jpg and store in the same "one" directory and when the script pass to directory "two" must convert the other1.pdf and other2.pdf to other1.jpg and other2.jpg and store inside same "two" directory not in other. If in "one and "two" directories there are .flv or any other extension different than pdf the script must ignore or not convert or touch the file.
This is an example but c:\data could have hundred of directories not just "one" and "two" and all the files inside each sub directory must respect the location and must be together where the original pdf file reside but never throw in one directory all the conversion.
Any modification to do this in the main script I posted?
Thank you