1.

Solve : Converting a GNU Make to a Windows .bat (recursive sub-dirs feeding an app)?

Answer»

I am trying to recursively feed pandoc all of the HTML files in a directory and sub-directories and have it generate one Markdown file.

I can get it to pull in all of the HTML files in the parent directory just fine (*.html) but to feed it the sub-directories I am having some...mmmm...problems.

A make file to do this looks like this:

TXTDIR=sources
HTMLS=$(wildcard *.html)
MDS=$(patsubst %.html,$(TXTDIR)/%.markdown, $(HTMLS))

.PHONY : all

all : $(MDS)

$(TXTDIR) :
mkdir $(TXTDIR)

$(TXTDIR)/%.markdown : %.html $(TXTDIR)
pandoc -F html -t markdown -s $< -o [emailprotected]

Not sure how to convert that to Windows .bat file though and hoping some kind soul on here may be ABLE to show me the way as my attempts so far haven't worked.

Thanks!
Welcome to CH

What do you wish to MAKE? Windows does no have one-one -one utilities like UNIX.

There is a BASH port to Windows. And a number of utilities have been ported. Often IT people like to do this because they got their first training on UNIX, not Windows.
http://win-bash.sourceforge.net/

Is this a one-time thing, or are you wanting to lot of work in a BASH environment? You can run Linux in a Virtual Machine and save yourself some time.
Running Ubuntu Linux in Windows XP using VMWARE

Linux can read NTFS, but makes some errors in the index upon writes. So you would want to have a FAT32 partition to get around this.
http://en.wikipedia.org/wiki/NTFSQuote from: Geek-9pm on June 29, 2012, 02:59:30 PM

Linux can read NTFS, but makes some errors in the index upon writes. So you would want to have a FAT32 partition to get around this.
http://en.wikipedia.org/wiki/NTFS
I've not run into that issue. Fairly sure they resolved it. I think that was a bug in some of the early writable NTFS FS implementations added to the Kernel.You are right. After kernel 2.6 there should be no problem. See the Linux item inn the Wikipedia link.
OR
http://en.wikipedia.org/wiki/NTFS#LinuxQuote from: Geek-9pm on June 29, 2012, 02:59:30 PM
Welcome to CH

What do you wish to MAKE? Windows does no have one-one -one utilities like UNIX.

I am just looking for the way to feed pandoc all files in the current, and all sub directories, that end in .html

In short, I am trying to convert html to Markdown for some Javadoc I have that is spread across the current, and child directories.

Thanks!I have no idea what pandoc is or what you use it for so maybe you can start by clarifying that.

If you want a list of all HTML files in a directory and sub directories and be able to use them you can do this.

Code: [Select]For /F "delims=" %%G in ('dir /b /a-d /s *.html') do echo %%GQuote from: Squashman on June 30, 2012, 11:47:42 AM
I have no idea what pandoc is or what you use it for so maybe you can start by clarifying that.

If you want a list of all HTML files in a directory and sub directories and be able to use them you can do this.

Code: [Select]For /F "delims=" %%G in ('dir /b /a-d /s *.html') do echo %%G

Pandoc is a conversion routine that can convert from HTML (and many others) into Markdown (and many others).

It just needs to know where to grab the files from.

For example this tells Pandoc the source is HTML format, the output is Markdown format, the output file is output and the input sopurce is all HTML files in the current directory:

pandoc -f html -t markdown -s *.html -o output

Can you break that down a little better for me.
I am looking at the pandoc documentation and from your example I can't tell what the input file is and what each of those options are. You certainly explained it in your description but you didn't say option F does this and option S does this.

Are you wanting to take all the HTML files and put them into one OUTPUT file or do you want each html file to have its own output file?

If your ran my existing batch file you will see that the variable %%G is showing each HTML file is it finding. You should be able to use that variable with your pandoc execution. Just remove the echo %%G and put your pandoc command there using %%G for your input file name.-f is from, -t is to, (as in format types) -s is source, -o is destination (for file names)Quote from: BC_Programmer on June 30, 2012, 05:46:54 PM
-f is from, -t is to, (as in format types) -s is source, -o is destination (for file names)
I read this webpage but I could not find any documentation that said -s is for source.
http://johnmacfarlane.net/pandoc/README.htmlnevermind. It's probably it's own switch (apparently, standalone). Most *nix style utilities will accept a "loose" file specification as their input.I see your question is already answered about what the switches stand for.

What you are suggesting then is something like this:

For /F "delims=" %%G in ('dir /b /a-d /s *.html') do pandoc -f html -t markdown -s %%G -o output

That look about right?

I'll give it shot.

Thanks!

Quote from: Squashman on June 30, 2012, 05:02:09 PM
Can you break that down a little better for me.
I am looking at the pandoc documentation and from your example I can't tell what the input file is and what each of those options are. You certainly explained it in your description but you didn't say option F does this and option S does this.

Are you wanting to take all the HTML files and put them into one OUTPUT file or do you want each html file to have its own output file?

If your ran my existing batch file you will see that the variable %%G is showing each HTML file is it finding. You should be able to use that variable with your pandoc execution. Just remove the echo %%G and put your pandoc command there using %%G for your input file name.
Quote from: BC_Programmer on June 30, 2012, 06:35:07 PM
nevermind. It's probably it's own switch (apparently, standalone). Most *nix style utilities will accept a "loose" file specification as their input.
The documentation just shows to put the input file as the last option in the command line with no switch so I am not sure where the OP is getting the documentation to use -s for the input file.Quote from: Squashman on July 01, 2012, 12:38:02 PM
The documentation just shows to put the input file as the last option in the command line with no switch so I am not sure where the OP is getting the documentation to use -s for the input file.


Yes, the -s shouldn't be there. Just leave it with the source file at the end.

What I ended up wish looks like this:

For /F "delims=" %%G in ('dir /b /a-d /s *.html') do pandoc -f html -t markdown -o %%G.md %%G

That will take each HTML file in the entire structure and create a Markdown version of it. Thanks!

One other question though. Is it possible to roll up all of the HTML files in a given sub directory into one output file instead of one file per input file?

For example:

subdir1
a.html
b.html
c.html

Instead of having a, b, and c, just have one file containing all three and name it subdir1 with the md EXTENSION (since it is Markdown format it will append the .md automatically).
Quote from: darrinps on July 02, 2012, 08:48:56 AM

One other question though. Is it possible to roll up all of the HTML files in a given sub directory into one output file instead of one file per input file?

For example:

subdir1
a.html
b.html
c.html

Instead of having a, b, and c, just have one file containing all three and name it subdir1 with the md extension (since it is Markdown format it will append the .md automatically).

This is untested:

Code: [Select]@echo off
for %%a in ("%cd%") do copy *.html "%%~nxa.md"


Discussion

No Comment Found