Link to home
Start Free TrialLog in
Avatar of coerrace
coerrace

asked on

jpg check on a batch and skip a task

Hello I have this code someone helped me here:

@echo off
forfile /p "c:" /s /m *.pdf" >junk.text
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

Open in new window


   This is the original link with all explanation and history:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28487439.html#a40232102

   Is working perfect no problem at all. What it does is look for PDF's inside all sub directories inside "c:\data\" then convert that pdf's to jpg and that jog is stored in the same directory the original pdf it is. For example we have just one sub directory inside "c:\data" called "one" it means "c:\data\one" and that sub directory "one" has 2 pdfs called 1.pdf and 2.pdf (of course is an example only names could be anything and sub directories is insde "c:\data" could be any number). Now if you run the script add inside "c:\data\one" 2 jpgs called 1.jpg and 2.jpg because like I mentioned before the converted jpgs must be with the name of the original pdf of where it was converted and saved in same location of that original pdf.
   Now the script does exactly like we want is prefect but someone could help us in add in the code a condition that if the jpg corresponding to one pdf exist in the directory and skip the conversion and continue with the other file and so on with all sub directories inside "c:\data" and all pdfs inside each sub directory of "c:\data". We want to do this because we add new sub directories to "c:\data" so frequent and there a re a lot of new sub directories and if we run the script process all and re-convert all the already converted files and there is no need to re-convert what it was converted because takes so long talking in days times.
   I hope someone can help.
Thank you
Avatar of oBdA
oBdA

That script can't work as listed. the "forfile" command should be "forfiles", and it will choke on any file that has more than one "." in it. Try it like this; the script is in test mode and will only display the "convert" commands it would normally run (and it will skip files for which a ".jpg" already exists). Remove the uppercase ECHO in line 7 to run it for real.
@echo off
setlocal
set SourceFolder=C:\Data
for /r "%SourceFolder%" %%a in ("*.pdf") do (
	echo Processing '%%~fa' ...
	if not exist "%%~dpna.jpg" (
		ECHO convert.exe "%%~fa" "%%~dpna.jpg"
	)
)

Open in new window

Avatar of coerrace

ASKER

oBdA appers is working just ine thing if you have source directory like "c:\data new exploration" with spaces not work it just worj for directories like ."c:\anydir" without spaces.
   Could you check to accept spaces in source directory?
Thank you
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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
Is working yes I was entering quotes "" is working all and script is more robust than o,d one to do the same.
Thank you