I built a program for scanning through nemory and presents all files and folders, in which you can now search for each files particular extension e.g .mp3-music.
This program contains two files;
1. My file and folders detector module
2. My Python3 program
To review the project correctly visit my GitHub account and download code for free.
FILE DETECTOR PY Download
class fileObject:
def __init__(self,name):
self.name=name
def isDir(self):
try:
with open(self.name, "r") as f:
pass
except IsADirectoryError:
return True
return False
Py program. Download
import os | |
from FileLooperModule import fileObject | |
os.chdir("/storage/emulated/0") | |
objects=[] | |
dirs=[] | |
files=[] | |
parent_cwd=os.getcwd() | |
changing_cwd=parent_cwd | |
#Function to load directories | |
def checkDir(x,p=''): | |
global objects | |
for i in os.listdir(): | |
i = fileObject(i) | |
objects.append(i) | |
for i in objects: | |
if i.isDir(): | |
dirs.append(p+i.name) | |
else: | |
files.append(i.name) | |
objects=[] | |
checkDir(changing_cwd) | |
use='' | |
if len(dirs) == 0: | |
pass | |
else: | |
for i in dirs: | |
changing_cwd=parent_cwd | |
changing_cwd=changing_cwd+'/'+i | |
os.chdir(changing_cwd) | |
checkDir(changing_cwd,p=i+"/") | |
#Sorting out each file extension | |
print(15*"="+"Music") | |
print([i for i in files if i.endswith(".mp3")]) | |
print(15*"*"+"Images") | |
print([i for i in files if i.endswith(".jpeg") or i.endswith(".png")]) | |
print(15*"+"+"Texts") | |
print([i for i in files if i.endswith(".txt") or i.endswith(".mhtml") or i.endswith(".pdf") or i.endswith(".html") or i.endswith(".py |
0 Comments
Please comment on our page thank you