A Python script implementation that is easy to use everyday

Source: Internet
Author: User
Tags python script

Directory

File Batch Rename

Bin file Merge

Body

1.python batch file renaming according to different conditions

Because the download of the TV series name is chaotic, but in accordance with the order of download time sequence, and manually rename or find software too troublesome, I realized a:

ImportOSImport TimedefRename (path): Num= 1#get all file paths under the current folderPathList =[Os.path.join (path, filename) forFileNameinchOs.listdir ()ifFilename.split ('.') [-1]! ='py']    #Sort by file modification time or creation time    #time.ctime (Os.path.getmtime (path))/time.ctime (os.path.getctime (path ))PathList =sorted (pathlist, key=LambdaPath' '. Join (Time.ctime (os.path.getmtime (Path)). Split (' ') [::-1]), reverse=False); #Rename a sorted file     forPathnameinchPathlist:newname= str (Num) +". The beautiful 漂亮的李慧珍"+". mp4"; Num+ = 1; Os.rename (Pathname, Os.path.join (path, newname))Print(pathname, newname);#get the current folder pathPath = Os.path.split (Os.path.realpath (__file__) ) [0];rename (Path)

2. Implement bin file merging based on offset value

#/usr/bin/pythonImportOSImportSYS fromstructImport*#Bin file MergedefBin_connect (Bin1, bin2, Outbin, offset): Fin1= Open (Bin1,'RB') fin2= Open (Bin2,'RB') Fout= Open (Outbin,'WB') Result=fin1.read () I=len (Result) whileI<int (Offset, 16): I+=1result+ = b' /'                 #a Bytes-like object is required, not ' str ', '->b 'Result + =Fin2.read () fout.write (Result) fin1.close ();    Fin2.close (); Fout.close ();#Example#combine.py-i bootloader.bin ramdisk.bin 0x10000-o combine.binifLen (sys.argv)! = 7orSYS.ARGV[1]! ='- I.' orSYS.ARGV[5]! ='- o':    Print('Usage:')    Print('convert binary format to hexadecimal format:')    Print('combine.py-i startfile endfile offset-o outfile') exit (0) Bin_connect (sys.argv[2], sys.argv[3], sys.argv[6], sys.argv[4])

A Python script implementation that is easy to use everyday

Related Article

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.