From 25fb31e5bc19308bd123260830213401b91d70d8 Mon Sep 17 00:00:00 2001 From: Minto Joseph Date: Fri, 8 Mar 2013 17:18:48 +0530 Subject: [PATCH 1/4] new file: QuickClean1.py --- QuickClean1.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 QuickClean1.py diff --git a/QuickClean1.py b/QuickClean1.py new file mode 100644 index 0000000..521ef1c --- /dev/null +++ b/QuickClean1.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +# QuickClean.py +# Version 0.04 + +""" +Quickly clean music, videos, images and documents into a different directory. +""" + +import argparse +import glob +import os +import shutil + + +parser = argparse.ArgumentParser(description='A quick way to clean out your \ + cluttered folders.') +parser.add_argument('-s', + '--source', + help='Directory you want to clean out. If no other \ + argumnets are provided, will create relevant \ + directories under source directory', + required=True) +parser.add_argument('-m', + '--music', + help='Directory you want to copy music files to. If \ + absolute path is not provided, will create \ + directory inside the source directory', + default='music', + required=False) +parser.add_argument('-p', + '--pictures', + help='Directory you want to copy picture files to. If \ + absolute path is not provided, will create \ + directory inside the source directory', + default='pictures', + required=False) +parser.add_argument('-v', + '--videos', + help='Directory you want to copy video files to. If \ + absolute path is not provided, will create \ + directory inside the source directory', + default='videos', + required=False) +parser.add_argument('-d', + '--documents', + help='Directory you want to copy document files to. If \ + absolute path is not provided, will create \ + directory inside the source directory', + default='documents', + required=False) + + +args = vars(parser.parse_args()) +source_dir=args.itervalues().next() +os.chdir(source_dir) + +file_types = { + "music": ["mp3", "flac", "aac"], + "pictures": ["png", "jpg", "bmp", "gif"], + "videos": ["avi", "mp4", "flv", "mkv", "mov"], + "documents": ["pdf", "xls", "xlsx", "pptx", "docx", "m", "ppt", "doc"], +} + + +all_files = glob.glob("*") + +for label, types in file_types.iteritems(): + for ext in types: + for fname in all_files: + if fname.endswith("." + ext): + try: + for key, value in args.iteritems(): + os.mkdir(value) + except OSError: + pass + shutil.copy(fname, value) + os.remove(fname) From 3d1fa5a154b7d67e8ea0490eaf2482431549ba47 Mon Sep 17 00:00:00 2001 From: Minto Joseph Date: Fri, 8 Mar 2013 18:33:09 +0530 Subject: [PATCH 2/4] modified: QuickClean1.py --- QuickClean1.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/QuickClean1.py b/QuickClean1.py index 521ef1c..72eaca0 100644 --- a/QuickClean1.py +++ b/QuickClean1.py @@ -69,10 +69,10 @@ for ext in types: for fname in all_files: if fname.endswith("." + ext): - try: for key, value in args.iteritems(): - os.mkdir(value) - except OSError: - pass - shutil.copy(fname, value) + try: + os.mkdir(value) + except OSError: + pass + shutil.copy2(fname,value) os.remove(fname) From ced9328140bf20a3a1a92d2e5274e4b04786c768 Mon Sep 17 00:00:00 2001 From: Minto Joseph Date: Fri, 8 Mar 2013 19:39:23 +0530 Subject: [PATCH 3/4] cleaned up the code renamed: QuickClean1.py -> QuickClean.py modified: QuickClean1.py --- QuickClean.py | 82 ++++++++++------------------------ QuickClean1.py | 116 +++++++++++++++++++------------------------------ 2 files changed, 67 insertions(+), 131 deletions(-) diff --git a/QuickClean.py b/QuickClean.py index c81dbfb..7a8a096 100644 --- a/QuickClean.py +++ b/QuickClean.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # QuickClean.py -# Version 0.03 +# Version 0.04 """ Quickly clean music, videos, images and documents into a different directory. @@ -50,65 +50,27 @@ default='documents', required=False) + args = parser.parse_args() os.chdir(args.source) - -# Parameters to clean. - -music = glob.glob("*.mp3") + \ - glob.glob("*.aac") + \ - glob.glob("*.flac") - -pictures = glob.glob("*.png") + \ - glob.glob("*.bmp") + \ - glob.glob("*.gif") + \ - glob.glob("*.jpg") + \ - glob.glob("*.JPG") + \ - glob.glob("*.jpeg") + \ - glob.glob("*.JPEG") - -videos = glob.glob("*.avi") + \ - glob.glob("*.mp4") + \ - glob.glob("*.flv") + \ - glob.glob("*.mkv") + \ - glob.glob("*.mov") - -documents = glob.glob("*.pdf") + \ - glob.glob("*.PDF") + \ - glob.glob("*.zip") + \ - glob.glob("*.doc") + \ - glob.glob("*.xls") + \ - glob.glob("*.ppt") + \ - glob.glob("*.docx") + \ - glob.glob("*.xlsx") + \ - glob.glob("*.pptx") + \ - glob.glob("*.m") - - -# Copies to destination directory, and then deletes the file. This is -# done because shutil's copy method has the ability to overwrite. - -for songs in music: - if not os.path.exists(args.music): - os.mkdir(args.music) - shutil.copy(songs, args.music) - os.remove(songs) - -for video in videos: - if not os.path.exists(args.videos): - os.mkdir(args.videos) - shutil.copy(video, args.videos) - os.remove(video) - -for picture in pictures: - if not os.path.exists(args.pictures): - os.mkdir(args.pictures) - shutil.copy(picture, args.pictures) - os.remove(picture) - -for document in documents: - if not os.path.exists(args.documents): - os.mkdir(args.documents) - shutil.copy(document, args.documents) - os.remove(document) +file_types = { + "music": ["mp3", "flac", "aac"], + "pictures": ["png", "jpg", "bmp", "gif"], + "videos": ["avi", "mp4", "flv", "mkv", "mov"], + "documents": ["pdf", "xls", "xlsx", "pptx", "docx", "m", "ppt", "doc"], +} + + +all_files = glob.glob("*") + +for label, types in file_types.iteritems(): + for ext in types: + for fname in all_files: + if fname.endswith("." + ext): + try: + os.mkdir(vars(args)[label]) + except OSError: + pass + shutil.copy2(fname, vars(args)[label]) + os.remove(fname) diff --git a/QuickClean1.py b/QuickClean1.py index 72eaca0..62e540f 100644 --- a/QuickClean1.py +++ b/QuickClean1.py @@ -1,78 +1,52 @@ #!/usr/bin/env python - -# QuickClean.py -# Version 0.04 - -""" -Quickly clean music, videos, images and documents into a different directory. -""" - -import argparse +#Quickly clean my music, videos and images into a different directory. +#QuickClean.py +#Version 0.02 import glob +import sys import os import shutil +import argparse -parser = argparse.ArgumentParser(description='A quick way to clean out your \ - cluttered folders.') -parser.add_argument('-s', - '--source', - help='Directory you want to clean out. If no other \ - argumnets are provided, will create relevant \ - directories under source directory', - required=True) -parser.add_argument('-m', - '--music', - help='Directory you want to copy music files to. If \ - absolute path is not provided, will create \ - directory inside the source directory', - default='music', - required=False) -parser.add_argument('-p', - '--pictures', - help='Directory you want to copy picture files to. If \ - absolute path is not provided, will create \ - directory inside the source directory', - default='pictures', - required=False) -parser.add_argument('-v', - '--videos', - help='Directory you want to copy video files to. If \ - absolute path is not provided, will create \ - directory inside the source directory', - default='videos', - required=False) -parser.add_argument('-d', - '--documents', - help='Directory you want to copy document files to. If \ - absolute path is not provided, will create \ - directory inside the source directory', - default='documents', - required=False) - - -args = vars(parser.parse_args()) -source_dir=args.itervalues().next() -os.chdir(source_dir) - -file_types = { - "music": ["mp3", "flac", "aac"], - "pictures": ["png", "jpg", "bmp", "gif"], - "videos": ["avi", "mp4", "flv", "mkv", "mov"], - "documents": ["pdf", "xls", "xlsx", "pptx", "docx", "m", "ppt", "doc"], -} - - -all_files = glob.glob("*") +parser = argparse.ArgumentParser(description='A quick way to clean out your cluttered folders.') +parser.add_argument('-s','--source', help='Directory you want to clean out. If no other argumnets are provided, will create relevant directories under source directory', required=True) +parser.add_argument('-m','--music', help='Directory you want to copy music files to. If absolute path is not provided, will create directory inside the source directory', default='music', required=False) +parser.add_argument('-p','--pictures', help='Directory you want to copy picture files to. If absolute path is not provided, will create directory inside the source directory', default='pictures', required=False) +parser.add_argument('-v','--videos', help='Directory you want to copy video files to. If absolute path is not provided, will create directory inside the source directory', default='videos', required=False) +parser.add_argument('-d','--documents', help='Directory you want to copy document files to. If absolute path is not provided, will create directory inside the source directory', default='documents',required=False) + + +args = parser.parse_args() +os.chdir(args.source) + + +#Parameters to clean. +music = glob.glob("*.mp3") + glob.glob("*.flac") + glob.glob("*.aac") +pictures = glob.glob("*.png") + glob.glob ('*.jpg') + glob.glob("*.bmp")+ glob.glob("*.gif") +videos = glob.glob("*.avi") + glob.glob("*.mp4") + glob.glob("*.flv") + glob.glob("*.mkv") + glob.glob("*.mov") +documents = glob.glob ('*.pdf') + glob.glob ('*.PDF') + glob.glob ("*.xls") + glob.glob ("*.xlsx") + glob.glob ("*.pptx") + glob.glob ("*.docx") + glob.glob("*.m") + glob.glob("*.ppt") + glob.glob("*.doc") + + +#Copies to destination directory, and then deletes the file. This is done because shutil's copy method has the ability to overwrite. +for songs in music: + if not os.path.exists(args.music): + os.mkdir(args.music) + shutil.copy(songs,args.music) + os.remove(songs) +for video in videos: + if not os.path.exists(args.videos): + os.mkdir(args.videos) + shutil.copy(video,args.videos) + os.remove(video) +for picture in pictures: + if not os.path.exists(args.pictures): + os.mkdir(args.pictures) + shutil.copy(picture,args.pictures) + os.remove(picture) +for document in documents: + if not os.path.exists(args.documents): + os.mkdir(args.documents) + shutil.copy(document,args.documents) + os.remove(document) -for label, types in file_types.iteritems(): - for ext in types: - for fname in all_files: - if fname.endswith("." + ext): - for key, value in args.iteritems(): - try: - os.mkdir(value) - except OSError: - pass - shutil.copy2(fname,value) - os.remove(fname) From 8f803fc7c396dc378cd0619a3e7c203528297d01 Mon Sep 17 00:00:00 2001 From: Minto Joseph Date: Fri, 8 Mar 2013 19:42:53 +0530 Subject: [PATCH 4/4] deleted: QuickClean1.py --- QuickClean1.py | 52 -------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 QuickClean1.py diff --git a/QuickClean1.py b/QuickClean1.py deleted file mode 100644 index 62e540f..0000000 --- a/QuickClean1.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -#Quickly clean my music, videos and images into a different directory. -#QuickClean.py -#Version 0.02 -import glob -import sys -import os -import shutil -import argparse - - -parser = argparse.ArgumentParser(description='A quick way to clean out your cluttered folders.') -parser.add_argument('-s','--source', help='Directory you want to clean out. If no other argumnets are provided, will create relevant directories under source directory', required=True) -parser.add_argument('-m','--music', help='Directory you want to copy music files to. If absolute path is not provided, will create directory inside the source directory', default='music', required=False) -parser.add_argument('-p','--pictures', help='Directory you want to copy picture files to. If absolute path is not provided, will create directory inside the source directory', default='pictures', required=False) -parser.add_argument('-v','--videos', help='Directory you want to copy video files to. If absolute path is not provided, will create directory inside the source directory', default='videos', required=False) -parser.add_argument('-d','--documents', help='Directory you want to copy document files to. If absolute path is not provided, will create directory inside the source directory', default='documents',required=False) - - -args = parser.parse_args() -os.chdir(args.source) - - -#Parameters to clean. -music = glob.glob("*.mp3") + glob.glob("*.flac") + glob.glob("*.aac") -pictures = glob.glob("*.png") + glob.glob ('*.jpg') + glob.glob("*.bmp")+ glob.glob("*.gif") -videos = glob.glob("*.avi") + glob.glob("*.mp4") + glob.glob("*.flv") + glob.glob("*.mkv") + glob.glob("*.mov") -documents = glob.glob ('*.pdf') + glob.glob ('*.PDF') + glob.glob ("*.xls") + glob.glob ("*.xlsx") + glob.glob ("*.pptx") + glob.glob ("*.docx") + glob.glob("*.m") + glob.glob("*.ppt") + glob.glob("*.doc") - - -#Copies to destination directory, and then deletes the file. This is done because shutil's copy method has the ability to overwrite. -for songs in music: - if not os.path.exists(args.music): - os.mkdir(args.music) - shutil.copy(songs,args.music) - os.remove(songs) -for video in videos: - if not os.path.exists(args.videos): - os.mkdir(args.videos) - shutil.copy(video,args.videos) - os.remove(video) -for picture in pictures: - if not os.path.exists(args.pictures): - os.mkdir(args.pictures) - shutil.copy(picture,args.pictures) - os.remove(picture) -for document in documents: - if not os.path.exists(args.documents): - os.mkdir(args.documents) - shutil.copy(document,args.documents) - os.remove(document) -