?
Solved

Batch file that automatically iterates each html file in a folder

Posted on 2014-12-08
4
Medium Priority
?
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 85

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 85

Accepted Solution

by:
oBdA earned 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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…
Starting up a Project
Suggested Courses

777 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