Solved

Batch file that automatically iterates each html file in a folder

Posted on 2014-12-08
4
340 Views
Last Modified: 2014-12-08
Greetings all,

I have a folder full of files, including HTML files and I need a batch file that will find and pass every html file through a CLI program.

docvert -e %out_file% %in_file% -t gts -l val

So,
%out_file% = the output file (same name as the in_file) but with the extension ".html" replaced with ".txt"
%in_file% = the source html file in the folder

I know that I can list out all *.html files by adding this line to a batch file:
for /r %in_file% in (*.htm) do echo %in_file%

Finally, I want to log each iteration in the do loop and how long it required.

Probably, something like this should be good enough...
echo Translation start %date% %time% >> log.txt

Thank you
0
Comment
Question by:sconnell
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 40487532
Try this; it's currently in test mode and will only display the docvert commands it would normally run; remove the uppercase ECHO in line 10 to run it for real.
@echo off
setlocal

set RootFolder=C:\Temp
set LogFile=C:\Temp\log.txt

for /r "%RootFolder%" %%a in (*.htm) do (
	echo [%Date%][%Time%] Processing '%%~a' ...
	>>"%LogFile%" echo [%Date%][%Time%] Begin '%%~a'
	ECHO docvert -e "%%~dpna.txt" "%%~a" -t gts -l val
	>>"%LogFile%" echo [%Date%][%Time%] End '%%~a'
)

Open in new window

0
 
LVL 4

Author Comment

by:sconnell
ID: 40487555
Hello oBdA,

Thank you so much.

Before I run this, a few questions:
1) Do I need setlocal?
2) I need this batch file to work in the current folder (that could be any folder)... so my plan is to make it available from anywhere by adding it to the path environment variable.
    That means that I wouldn't want use an absolute root folder... nor specify an absolute location for the log file because the log file should be saved to the current folder.

Thank you
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40487577
"setlocal" makes sure that variables set in the script don't spill over into the command prompt calling the script; I use by default. The current folder is in the default variable %cd%:
@echo off
setlocal

set RootFolder=%cd%
set LogFile=%cd%\log.txt

for /r "%RootFolder%" %%a in (*.htm) do (
	echo [%Date%][%Time%] Processing '%%~a' ...
	>>"%LogFile%" echo [%Date%][%Time%] Begin '%%~a'
	ECHO docvert -e "%%~dpna.txt" "%%~a" -t gts -l val
	>>"%LogFile%" echo [%Date%][%Time%] End '%%~a'
)

Open in new window

0
 
LVL 4

Author Closing Comment

by:sconnell
ID: 40487705
Brilliant! Works exactly as required!

Thank you.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now