#!/usr/local/bin/python3 # # Move files to directories 0-z based on 1st char of filename # https://gist.github.com/idolpx/eadd12cb15daa61d9253f325a0381778 # # Jaime Idolpx # import os, re, py7zr #with py7zr.SevenZipFile('sample.7z', mode='r') as z: # z.extractall() #def extractCB(p1, p2): # print( '[' + p1 + '] [' + p2 + ']' ) # Getting the current work directory (cwd) src_dir = os.getcwd() + os.sep dest_dir = os.getcwd() + os.sep def walk_through_files(path, file_extension=''): for (dirpath, dirnames, filenames) in os.walk(path): for filename in filenames: if filename.endswith(file_extension): yield [dirpath + os.sep, filename] for path, file in walk_through_files ( src_dir ): #print ( path + " + " + file ) outdir = file[0].lower() + os.sep # print ( outdir ) if ( not os.path.exists( outdir ) ): os.mkdir( outdir ) # Clean up filename outfile = file.lower() outfile = re.sub(r' |\(.*\)|\'|,', '', outfile) outfile = re.sub(r'\.prg$', '', outfile) print ( path + file + " -> " + dest_dir + outdir + outfile ) # Rename ISO file os.rename( path + file, outdir + outfile ) print( 'Done!' )