-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManipulateFiles.py
More file actions
38 lines (30 loc) · 1.05 KB
/
ManipulateFiles.py
File metadata and controls
38 lines (30 loc) · 1.05 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
import os
class ManipulateFiles:
def __init__(self, folder):
self.folder = folder
def listFiles(path):
files_list = []
path = os.scandir(path)
for files in path:
if files.is_file():
files_list.append(files.name)
return files_list
def listSubfolders(path):
subfolders_list = []
path = os.scandir(path)
for subfolders in path:
if not subfolders.is_file():
subfolders_list.append(subfolders.name)
return subfolders_list
def createSubfolders(path, destination):
has_subfolder = False
subfolders = ManipulateFiles.listSubfolders(path)
for objects in subfolders:
if objects == destination:
has_subfolder = True
if(not has_subfolder):
os.mkdir(f"{path}/{destination}")
return
def moveFiles(path, file, destination):
os.rename(f"{path}/{file}", f"{path}/{destination}/{file}")
return