Skip to content

Commit 25d7f63

Browse files
Merge pull request #879 from neelshah2409/main
Folder Content Sorter
2 parents 8c135b6 + fe214e7 commit 25d7f63

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed
31.5 KB
Loading
37 KB
Loading
20.8 KB
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Folder Content Sorter
2+
3+
## Aim
4+
5+
To sort all the files of folder properly
6+
7+
## Purpose
8+
9+
To locate the files as per their extension or type.
10+
11+
## Short description of package/script
12+
13+
- Here we first fetch the path of the current folder and than get the extension of each file and then sort the file according to that
14+
-For example ,if extensions are .pdf , .docx then it will go to documents folder simillarly for images>.jpg,.png,.gif ,for videos > .mp4,.wmv and for apps>.apk,.exe .
15+
16+
17+
- List out the libraries imported > os , shutil
18+
19+
20+
## Workflow of the Project
21+
22+
- First have the script in the same folder in whuch you wanted to sort the files and then run the script so as a result different folders will be formed accordingly.
23+
24+
25+
## Setup instructions
26+
- Fisrt install the libraries and then run the script so all the files will be allocated in images,videos,apps and documents folder respectively.
27+
28+
29+
## Output
30+
![image](Images/before_running(folder_content_sorter).png)
31+
![image](Images/after_running(folder_content_sorter).png)
32+
![image](Images/output(folder_content_sorter).png)
33+
34+
35+
## Author(s)
36+
37+
Neel Shah
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import shutil
3+
4+
#getting path of current folder/directory
5+
current_dir = os.path.dirname(os.path.realpath(__file__))
6+
7+
for filename in os.listdir(current_dir):
8+
#for images
9+
if filename.endswith(('.jpg', '.png', '.gif')):
10+
if not os.path.exists("Images"):
11+
os.makedirs('Images')
12+
shutil.copy(filename, 'Images')
13+
os.remove(filename)
14+
print('Images folder done')
15+
#for documents
16+
if filename.endswith(('.pdf', '.docx')):
17+
if not os.path.exists("Documents"):
18+
os.makedirs('Documents')
19+
shutil.copy(filename, 'Documents')
20+
os.remove(filename)
21+
print('Documents folder done')
22+
#for apps or softwares
23+
if filename.endswith(('.apk', '.exe')):
24+
if not os.path.exists("Apps"):
25+
os.makedirs('Apps')
26+
shutil.copy(filename, 'Apps')
27+
os.remove(filename)
28+
print('Apps folder done')
29+
#for videos
30+
if filename.endswith(('.mp4', '.wmv')):
31+
if not os.path.exists("Videos"):
32+
os.makedirs('Videos')
33+
shutil.copy(filename, 'Videos')
34+
os.remove(filename)
35+
print('Videos folder done')
36+
#after completing the task printing all done
37+
print('all done')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Libraries used:
2+
- shutil
3+
- os

0 commit comments

Comments
 (0)