• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

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
0
coerrace
Asked:
coerrace
  • 2
  • 2
1 Solution
 
oBdACommented:
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

0
 
coerraceAuthor Commented:
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
0
 
oBdACommented:
It should work for folders with a space in them as well; just don't add the quotes already when setting the variable:
@echo off
setlocal
set SourceFolder=C:\data new exploration
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

0
 
coerraceAuthor Commented:
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now