我正在尝试将根目录中的多个文件连接到单个文件。但是我坚持这些问题:
我正在使用Python3,而我的操作系统是Windows 7。
我已经推进了以下代码:
import os, shutil
def concatFiles():
path = 'D:\\concat\\';
scriptFullFilename = 'scriptFull.sql'
if os.path.isfile(path + scriptFullFilename):
os.remove(scriptFullFilename)
files = os.listdir(path);
filenames = [f for f in files if f.endswith('.sql')]
newLine = "\n"
with open(path + scriptFullFilename, mode='wb') as outfile:
for fname in filenames:
with open(fname,'rb') as source:
shutil.copyfileobj(source, outfile, 1024*1024*10)
print('Done')
if __name__ == "__main__":
concatFiles();