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