-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.py
49 lines (36 loc) · 1.06 KB
/
files.py
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
import os
import shutil
def get_total_files(directory, level=0):
"""
Returns total files in a folder.
---------
Default to same folder without sub-directories.
directory: the folder location.\n
level: (default 0) change if you want to span all subdirectories
"""
total_files = 0
walk_path = os.walk(directory)
for _, folder, files in walk_path:
total_files += len(files)
if level == 0:
break
return total_files
def get_file_list(directory, level=0):
"""
Returns file list of a folder.
---------
Default to same folder without sub-directories.
directory: the folder location.\n
level: (default 0) change if you want to span all subdirectories
"""
walk_path = os.walk(directory)
for _, folder, files in walk_path:
return files
def move_files(source, target):
"""
Move files to folder.
----------
source: the file path.
target: the target folder name.\n
"""
shutil.move(source, target)