Solved Anyone think of a way to do this with a batch file?

March 17, 2014 at 12:46:48
Specs: Windows 7
I need a way to get a program to treat .htmlz files (which it doesn't recognize) as .zip (which it does), anyone think of a way to do this with a batch file or similar?

Could I set the file association of .htmlz files to a batch file that would create a copy (of the original .htmlz file) renamed to .zip in a temp folder and then open it with my reader program?

To explain - I have a database program that outputs htmlz files (zipped html) and a preferred reader that only recognizes .zip (zipped html). If I rename the file the reader can open it perfectly but it's then not accessible to the database, and the database also uses .zip for another purpose so it all gets confused.
Thanks.


See More: Anyone think of a way to do this with a batch file?

Report •


#1
March 18, 2014 at 10:02:08
✔ Best Answer
::====== script starts here ===============
::
:: hz.bat 2014-03-18 23:42:13.92
@echo off & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=* delims= " %%a in ('dir/b *.htmlz') do (
copy "%%a" "%%~Na.zip"
reader "%%~Na.zip"
)
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
March 18, 2014 at 10:20:56
::designed as a drag and drop convertor.
cd \
::enter your working path on the next line, unless its the standard
::cd c:\workingpath\zips\
if %~x1 equ .htmlz rename %~n1.htmlz %~n1.zip
::this is assumeing you can use the below format to open.
call reader.exe %~n1.zip
rename %~n1.zip %~n1.htmlz
edit too slow, the above is probably better knowing the poster.
::mike

message edited by mikelinus


Report •

#3
March 18, 2014 at 11:49:32
Using hard links instead of file copies:
for %%a in (*.htmlz) do if not exist "%%~Na.zip" mklink /h "%%a" "%%~Na.zip"

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
March 19, 2014 at 11:46:17
Mechanix2Go your solution worked perfect first time, but after about a day it stopped working and I cannot figure out why. I've remade the batch file several times, reset the file association, checked the program link but nothing. The batch is just exiting and nothing is being done, no zip created. I tried adding a Pause to the end of the code but still just flashes and gone.

Report •

#5
March 19, 2014 at 12:00:43
Razor2.3, Sorry, can you be a bit more specific, I'm not great at this. not sure if that is meant to be an alternative line of code in Mecanix2Go's or what? Full code please, thanks.

Report •

#6
March 19, 2014 at 13:40:18
It's a complete script, unless you need to launch the reader, as Mechanix2Go does in his script, but if M2G's doesn't work, I doubt mine would either.

How To Ask Questions The Smart Way


Report •

#7
March 19, 2014 at 14:23:38
I have M2G's working again. Still like to give yours a try, I do need to launch the reader so what's the complete code?
Thanks

Report •

#8
March 20, 2014 at 21:10:56
for %%a in (*.htmlz) do (
  if not exist "%%~Na.zip" mklink /h "%%a" "%%~Na.zip"
  reader "%%~Na.zip"
)

How To Ask Questions The Smart Way


Report •

#9
March 22, 2014 at 08:22:05
This works perfect outside the database but unfortunately not from within.

When run from within the database (Calibre) with Echo on I get:
================================================
C:\Users\-\Desktop\books\Calibre Portable>for /F "tokens=* delims= " %a in ('dir
/b *.htmlz') do (
copy "%a" "%~Na.zip"
"C:\Program Files (x86)\ubook\uBook.exe" "%~Na.zip"
)
File Not Found

C:\Users\-\Desktop\books\Calibre Portable>Pause
Press any key to continue . . .
============================================

When run outside of the database I get:

============================================
C:\Users\-\Desktop\books\Calibre Portable\Calibre Library\Caroline B. Cooney\Fre
eze Tag (6)>for /F "tokens=* delims= " %a in ('dir/b *.htmlz') do (
copy "%a" "%~Na.zip"
"C:\Program Files (x86)\ubook\uBook.exe" "%~Na.zip"
)

C:\Users\-\Desktop\books\Calibre Portable\Calibre Library\Caroline B. Cooney\Fre
eze Tag (6)>(
copy "Freeze Tag - Caroline B. Cooney.htmlz" "Freeze Tag - Caroline B. Cooney.zi
p"
"C:\Program Files (x86)\ubook\uBook.exe" "Freeze Tag - Caroline B. Cooney.zip"

)
1 file(s) copied.
============================================

Looks like it's trying to copy and convert the database instead of the book? Anyone help me out with this?

message edited by Splodgeness


Report •

#10
April 2, 2014 at 09:53:23
Got this working in the end with:

======================================
echo off
setlocal ENABLEDELAYEDEXPANSION
set str=%1
set name=%str:HTMLZ=ZIP%
copy %1 %name%
start "" /wait "C:\Program Path\reader.exe" %name%
del %name%
======================================


Report •


Ask Question