-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileOrganizer.py
More file actions
59 lines (32 loc) · 1.38 KB
/
FileOrganizer.py
File metadata and controls
59 lines (32 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import shutil
# Main Function
def main():
# Initial prompt
print("This script will arrange files into new folders according to their"\
" file type.\n")
# Asking user for the target folder
targetFolder = input("Enter the directory for the target folder:\n")
# Getting list of the files in the target folder
filesList = os.listdir(targetFolder)
# Looping through the list of files
for file in filesList:
if os.path.isfile(targetFolder + "\\" + file):
# Getting file extension and directory
fileSplit = os.path.splitext(file)
extension = fileSplit[1]
currentFileLocation = targetFolder + "\\" + file
# Naming organized folder
newFolderDir = targetFolder + "\\" + extension[1:]
newFileDir = newFolderDir + "\\" + file
# Creating organized folder if it does not exist
if not os.path.exists(newFolderDir):
os.makedirs(newFolderDir)
# Putting file into newly made directory
shutil.move(currentFileLocation, newFileDir)
# Putting file into previously made directory
else:
shutil.move(currentFileLocation, newFileDir)
# When the scipt is run
if __name__ == "__main__":
main()