From ce979ae5db36bc2abdbfb17efd97ee0af36d965d Mon Sep 17 00:00:00 2001 From: theavee Date: Mon, 14 Jan 2019 00:00:32 +0600 Subject: [PATCH 1/2] python3 program for rearrange file --- rearrange-files/rearrange-files.py | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 rearrange-files/rearrange-files.py diff --git a/rearrange-files/rearrange-files.py b/rearrange-files/rearrange-files.py new file mode 100644 index 00000000000..570887141ac --- /dev/null +++ b/rearrange-files/rearrange-files.py @@ -0,0 +1,40 @@ +import os +import shutil + +class RearrangeFile(object): + def __init__(self): + self.folder_path = os.getcwd() + + def all_files(self): + self.list_of_all_files = os.listdir(self.folder_path) + + + def make_folder_and_return_name(self, foldername): + if os.path.exists(foldername) is False: + os.mkdir(foldername) + else: + foldername = foldername + str(2) + os.mkdir(foldername) + return foldername + + + def check_folder_existance(self): + for i in range(len(self.list_of_all_files)): + if self.list_of_all_files[i].endswith('.pdf'): + if os.path.exists('pdfs'): + shutil.move(self.folder_path+'/'+self.list_of_all_files[i] ,self.folder_path+'/pdfs' ) + else: + os.mkdir('pdfs') + + elif self.list_of_all_files[i].endswith('jpg'): + if os.path.exists('jpgs'): + shutil.move(self.folder_path+'/'+self.list_of_all_files[i] ,self.folder_path+'/jpgs' ) + else: + os.mkdir('jpgs') + + + +if __name__ == "__main__": + re = RearrangeFile() + re.all_files() + re.check_folder_existance() \ No newline at end of file From 28075c8bd630275bde076ba4f491ef746528064e Mon Sep 17 00:00:00 2001 From: avee chakraborty Date: Mon, 14 Jan 2019 00:19:22 +0600 Subject: [PATCH 2/2] Update rearrange-files.py --- rearrange-files/rearrange-files.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rearrange-files/rearrange-files.py b/rearrange-files/rearrange-files.py index 570887141ac..7ad7ed66c51 100644 --- a/rearrange-files/rearrange-files.py +++ b/rearrange-files/rearrange-files.py @@ -1,3 +1,7 @@ +#author : Avee Chakraborty +#department of software engineering, Daffodil inernational University +#Bangladesh + import os import shutil @@ -37,4 +41,4 @@ def check_folder_existance(self): if __name__ == "__main__": re = RearrangeFile() re.all_files() - re.check_folder_existance() \ No newline at end of file + re.check_folder_existance()