Converting Refer/BibIX to Excel format

As I promised, I come up with a clean code for converting the Refer/BibIX ( also Zotoro exported collection ) to a clear Excel format.

#! /usr/bin/env python

import sys
import os

def index_2d(myList, v):
	output = ""
	for i, x in enumerate(myList):
		if v in x:
			output += x[3:]
	return output

txt = ""
xls = ""

directory = sys.argv[1]

if len(sys.argv) < 1:
	sys.exit('Usage: ./ directory')

if not os.path.exists(directory): 
	exit('Directory not found!.\nUsage: ./ directory')

files = os.listdir(directory)

for theFile in files:
	with open(directory+'/'+theFile) as infile:
		for line in infile:
			txt += line

TagsMap = [[0,'%0','ReferenceType'], [1,'%A','Author'], [2,'%T','Title'], [3,'%8','Date'], [4,'%B','BookTitle'], 
[5,'%D','Year'], [6,'%N','Issue'], [7,'%P','Pages'], [8,'%U','URL'], [9,'%V','Volume'], [10,'%X','Abstract'], 
[11,'%I','Publisher'], [12,'%J','JournalName'], [13,'%K','Keywords'], [14,'%E','Editor'], [15,'%F','Label'], 
[16,'%C','PlacePublished'], [17,'%S','TertiaryTitle'], [18,'%Y','Translator'], [19,'%Z','Notes'], 
[20,'%6','NumberofVolumes'], [21,'%L','CallNumber'], [22,'%M','AccessionNumber'], [23,'%7','Edition'], 
[24,'%9','TypeofWork'], [25,'%?','SubsidiaryAuthor'], [26,'%@','ISBN|ISSN'], [27,'%!','ShortTitle'], 
[28,'%[','OriginalPublication'], [29,'%]','ReprintEdition'], [30,'%*','ReviewedItem'], [31,'%+','AuthorAddress'], 
[32,'%^','Caption'], [33,'%1','Custom1'], [34,'%2','Custom2'], [35,'%3','Custom3'], [36,'%4','Custom4'], 
[37,'%#','Custom5'], [38,'%$','Custom6'], [39,'%&','Section']]

Records = txt.split('\r\n\r\n')

# adding the titles of the columns
for i,tag,title in TagsMap:
	if i<len(TagsMap)-1: xls += TagsMap[i][2] + '\t'
	else: xls += TagsMap[i][2] + '\n'

for record in Records:
	Fields = record.split('\r\n')
	for i,tag,title in TagsMap:
		if i<len(TagsMap)-1: xls += index_2d(Fields,tag) + '\t'
		else: xls += index_2d(Fields,tag) + '\n'

f = open(directory+'/output.xls','w')

exit("now you can open the output.xlswith excel")