Original Python Bulk operations files, batch merge

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.