Solved

Batch file that automatically iterates each html file in a folder

Posted on 2014-12-08
4
338 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 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
"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
Comment Utility
Brilliant! Works exactly as required!

Thank you.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

772 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

17 Experts available now in Live!

Get 1:1 Help Now