Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### -*- coding: utf-8 -*-
- '''moverrr.py - files autosorter script
- - Moves EVERY file in dir with corresponding file's type name except files,
- listed in ex() and files with no extensions
- '''
- __version__ = "1.0.2r"
- __date__ = "13.04.2012"
- _news_ = \
- '''-----
- TODO:Change code to better fit into funcional programming idiom
- NEW: Files with unicode name now sorting properly
- NEW: Improved code readability
- NEW: Porting to Python 3.x
- NEW: Renamed to moverrr
- '''
- import os, sys, locale, codecs
- from shutil import move
- sys.stdout = sys.stdout.detach()
- sys.stdout = codecs.getwriter('cp866')(sys.stdout, errors='replace')
- ##sys.stdout = codecs.getwriter('utf-8')(sys.stdout, errors='replace')
- ex=("py","pyc","pyw","ini","ico","bat","exe",
- "lnk","DMF","DFMr","download","sys")
- def main(path):
- ## print('*0*', sys.stdout)
- count=0
- whitelist=[] #белый список стал локальным - v1.0.2k
- if path:
- print("*1* Directory to sort:", path)
- else:
- path=os.getcwd()
- print("Directory to sort:", path)
- #detecting and checking files in directory:
- filelist = [e for e in os.listdir(path) if os.path.isfile(e) and not e.endswith(ex)]
- for file in filelist:
- if file.rfind('.')!=-1:
- whitelist.append(file)
- count+=1
- elif file.rfind('.')==-1:
- print('no extension:', file)
- pass
- else:
- print('unknown error with', file)
- pass
- if whitelist: print('white list:', whitelist)
- else: print('white list is empty!')
- moveit(whitelist, count)
- def moveit(wlist,count):
- moved=0
- ext=''
- for file in wlist:
- ext=file[file.rfind('.')+1:]
- print('\'.%s\' file detected' % ext)
- #create dir with file-type name:
- try: os.mkdir(".\\%s\\" % ext)
- except OSError: pass
- #moving files into created directory
- if not os.path.exists(".\\%s\\%s" % (ext, file)): #если файла в директории нет,
- move(file, ".\\%s\\" % ext) #то перемещаем текущий файл
- moved+=1
- print('\'%s\' moved into \'%s\'' % (file, ext))
- else: print('skipped: \'%s\' already exists in \'%s\'' % (file, ext))
- if count:
- print('-'*32)
- print('%d of %d files processed' % (moved, count))
- else: print("nothing to move! :'<")
- if __name__ == "__main__":
- print('-'*32)
- print(
- '''Auto files sorter v%s by crad, %s
- I like to move it move it! :D
- %s''' % (__version__, __date__, _news_))
- print('black list:',ex)
- main(sys.argv[1:])
- # main("e:\\downloads\\")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement