Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Batch file that automatically iterates each html file in a folder

Posted on 2014-12-08
4
Medium Priority
?
359 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:Shawn Connelly
[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:Shawn Connelly
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:Shawn Connelly
ID: 40487705
Brilliant! Works exactly as required!

Thank you.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

604 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