我正在尝试创建一个运行它的脚本,您可以将PDF标记为书签,然后运行分离脚本来分隔页面。然而,这个书签它们的脚本意味着不要重命名它们,但它目前不是,我不明白为什么。
这是我的代码,我需要绝望的帮助:
with open('+Renamed.csv', 'ab') as fout:
writer = csv.writer(fout)
for filename in os.listdir(path):
filepath = os.path.join(path, filename)
filename_no_ext, ext = os.path.splitext(filename)
if ext.lower() == '.pdf':
n = str(idx).zfill(8)
new_filename = name_fmt % (ftoday, n)
new_filepath = os.path.join(path, new_filename)
new_filename_no_ext, ext = os.path.splitext(new_filename)
while new_filename_no_ext in db_list:
idx += 1
n = str(idx).zfill(8)
new_filename = name_fmt % (ftoday, n)
new_filepath = os.path.join(path, new_filename)
new_filename_no_ext, ext = os.path.splitext(new_filename)
while os.path.exists(new_filepath):
cmd = 'INSERT into [BLACKSTONE].[dbo].[Filename] ' \
'VALUES (?)'
cursor.execute(cmd, new_filename_no_ext)
cnxn.commit()
idx += 1
n = str(idx).zfill(8)
new_filename = name_fmt % (ftoday, n)
new_filepath = os.path.join(path, new_filename)
new_filename_no_ext, ext = os.path.splitext(new_filename)
idx += 1
print filepath
try:
os.rename(filepath, new_filepath)
print new_filepath
except:
print >>sys.stderr, 'Unable to rename:', filepath
sys.exit()
请帮助,我已经尝试完成这个大约一个周末了,我不明白为什么没有重命名,只是意味着不要重命名+ Renamed文件夹中的文件,请告诉我,如果你'我想看看整个代码。
谢谢!