Solved

Batch file that automatically iterates each html file in a folder

Posted on 2014-12-08
4
348 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 84

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 84

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
In this post we will learn different types of Android Layout and some basics of an Android App.

685 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