我有这个批处理文件应该运行一个python脚本来转换脚本所在的同一个文件夹中的一堆文件,事情是它对我不起作用,很多其他人已成功使用它对文件的任何改动......所以我希望有人可以解雇并帮助我。
附加信息:脚本是用python 2.5编写的,据说直到python 2.6.6,我使用Win7并安装了Python2.6.4,UAC禁用。
批次:
strings_bin_converter.py all
Python脚本:
# strings_bin_converter.py (c) 2006 Stefan Reutter (alias alpaca)
# Version 0.72
# A script to convert a number of MTW2 .strings.bin files to their .txt counterparts
import sys
import codecs
import struct
import os
def convertFile(filepath):
"""
Takes a type 2 .strings.bin file and converts it to a text file
"""
f = open(filepath+'.strings.bin', 'rb')
(style1,) = struct.unpack('h',f.read(2))
(style2,) = struct.unpack('h', f.read(2))
if style1 == 2 and style2 == 2048:
fw = codecs.open(filepath, encoding='UTF-16', mode='w')
fw.write(unicode(struct.pack('HH',0xFFFE,0xAC00),'UTF-16')+'\r\n')
(length,) = struct.unpack('i',f.read(4))
for string in range(length):
(strlen,) = struct.unpack('h', f.read(2))
tagstr = ''
for i in range(strlen):
tagstr += unicode(f.read(2), 'UTF-16')
(strlen,) = struct.unpack('h', f.read(2))
screenstr = ''
for i in range(strlen):
tempstr = f.read(2)
(e,) = struct.unpack('H',tempstr)
if e == 10:
screenstr += '\\n'
else:
screenstr += unicode(tempstr, 'UTF-16')
fw.write('{'+tagstr+'}'+screenstr+'\r\n')
fw.close()
f.close()
if sys.argv[1] == 'all':
arr = []
i = 1
for filepath in os.listdir(''):
if filepath.find('.strings.bin') > -1:
arr.append(filepath.split('.strings.bin')[0])
for filepath in arr:
print 'Converting file '+filepath+'('+str(i)+' of '+str(len(arr))+')'
convertFile(filepath)
i+=1
else:
for i in range(len(sys.argv)-1):
path = sys.argv[i+1]
convertFile(path)
这是我在运行批处理后在CMD屏幕上出现的错误:
Traceback (most recent call last):
File "C:\strings_bin_converter_0_7_2\strings_bin_converter.py", line 39, in <m
odule>
if sys.argv[1] == 'all':
IndexError: list index out of range
EDIT 在这里找到了一个解决方法:Python Script, args not transferred to Script