Skip to content

Commit 29cb12d

Browse files
Merge pull request KrishGaur1354#16 from mistracked/file-categorizer
Add File Categorizer
2 parents 35e7cdb + fbfece1 commit 29cb12d

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

File-Categorizer/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<h1>File Organizer</h1>
2+
3+
Basically assembles files that share the same extension into a folder.
4+
5+
![screenshot](https://user-images.githubusercontent.com/107259402/193411368-360aef5e-1b81-481f-8272-f484ac81b787.png)
6+
7+
8+
![Personal-Python-Projects](https://socialify.git.ci/KrishGaur1354/Personal-Python-Projects/image?font=Source%20Code%20Pro&language=1&name=1&owner=1&pattern=Circuit%20Board&theme=Dark)
9+
10+
<h3><i>Here, I will publish my Personal Python Projects whenever I get the time.</i></h3>
11+
12+
## Connect with me
13+
<a href="https://twitter.com/ThatOneKrish">
14+
<img width="30px" src="https://www.vectorlogo.zone/logos/twitter/twitter-official.svg" />
15+
</a>&ensp;
16+
<a href="https://www.instagram.com/ThatOneKrish/">
17+
<img width="30px" src="https://www.vectorlogo.zone/logos/instagram/instagram-icon.svg" />
18+
</a>&ensp;

File-Categorizer/file-categorizer.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
import shutil
3+
4+
ld = os.listdir()
5+
6+
for file in ld:
7+
if not '.' in file or os.path.isdir(file):
8+
continue
9+
else:
10+
if file == os.path.basename(__file__):
11+
continue
12+
ext = file.split('.')[-1]
13+
directory = ext.upper()+'s'
14+
15+
if directory in ld:
16+
print(f'Skipping {directory} directory...')
17+
else:
18+
print(f'Creating {directory} directory...')
19+
os.mkdir(directory)
20+
ld.append(directory)
21+
22+
try:
23+
shutil.move(file, directory)
24+
print(f'File {file} moved successfully!\n')
25+
except shutil.Error as e:
26+
print(e)
27+
continue

File-Categorizer/screenshot.png

31.1 KB
Loading

0 commit comments

Comments
 (0)