zim-wiki team mailing list archive
-
zim-wiki team
-
Mailing list archive
-
Message #00248
Re: How to use txt2tags across folders?
On Tue, May 5, 2009 at 22:16, Jaap Karssenberg
<jaap.karssenberg@xxxxxxxxx> wrote:
> untested example script:
>
> #!/usr/bin/python
> import sys
> dir = sys.argv[1]
> for root, dirs, files:
# The above line should be:
for root, dirs, files in os.walk(dir):
> for file in files:
> if file.endswith(".t2t"):
> fh = open(root+'/'+file)
> for i in range(4):
> fh.readline() # skip 4 lines of headers
> for line in fh:
> sys.stdout.write(line)
>
# Mixing readline and "for line in fh" is AFAIK not recommended
# because of internal buffering issues. More reliable:
flines = iter(open(root+'/'+file))
for i in range(4):
flines.next() # skip 4 lines of headers
for line in flines:
sys.stdout.write(line)
# Or better yet (doesn't assume 4 lines):
flines = iter(open(root+'/'+file))
for line if flines: # skip headers
if line.strip() == "":
break
for line in flines:
sys.stdout.write(line)
> This script would write all content to the terminal, so you can redirect it
> into a single file.
>
--
Beni <cben@xxxxxxxxxxxx>
References