Several recent small partners in the manual merge some text files, feel can be implemented in Python batch, there is this code
1 ImportOS2 ImportRe3 ImportSYS4 5 defPrintenter (F1):#line-wrapping between every two files6F1.write ("\n\n\n")7 forIinchRange (23) :8F1.write ("☆★")9F1.write ("\n\n\n")Ten One defMysplit (name, c):#Split Operation AList1 =list (name) - List1.reverse () -List2 ="". Join (List1) theList3 =List2.split (c) - returnList3[0] - - defGetName (names):#gets the file name that will be read +S1 = mysplit (names,"\\") -S2 = mysplit (S1,".") + returnS2 A at defvisitdir (Path, dirfile): -Li =os.listdir (path) -F1 = open (Dirfile,"a") - forPinchLi: -pathname =os.path.join (Path, p) - if( notos.path.isfile (pathname)): in Visitdir (pathname,dirfile) - Else : tofilename = getName (pathname)#Get file name + Print(filename) -f = open (pathname,"R") theLines =F.read () *lines = filename +"\ n"+Lines $ F1.writelines (lines)Panax Notoginseng printenter (F1) - f.close () the f1.close () + A if __name__=="__main__" : thePath = R"E:\programming\dev_c++\acm\algorithm" +Dirfile ="MyACM.txt" -Visitdir (Path, dirfile)Bulk Operations Files
This code is used to bulk merge a large number of files into a file
Create a new Python file and copy the code inside
Change the value of path in the penultimate line in the code to the path of the file you want to bulk manipulate
Change the value of the Dirfile in the penultimate line of the code to the target file that you want to save.
Four, the operation can
Python version: 3.4.0
[Original]python batch operation file, batch merge