-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
74 lines (61 loc) · 2.23 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import time as Time
from datetime import datetime, time
import tkinter
from tkinter import filedialog
import os
import multiprocessing
from multiprocessing import Manager
import keyboard
#list of filetypes to ignore
IGNORE_LIST = [".plx", ".fig", ".jpg"]
root = tkinter.Tk()
root.withdraw()
def get_filepath():
try:
currdir = os.getcwd()
tempdir = filedialog.askdirectory(parent=root, initialdir=currdir, title='Please select DeepLabCut directory')
if len(tempdir) > 0:
print("You chose: %s" % tempdir)
else:
raise Exception("Error: No file was selected")
except:
tempdir = get_file()
return tempdir
def get_file():
try:
currdir = os.getcwd()
tempdir = filedialog.askopenfilename(parent=root, initialdir=currdir, title='Please select the DeepLabCut model config')
if len(tempdir) > 0:
print("You chose: %s" % tempdir)
else:
raise Exception("Error: No file was selected")
except:
tempdir = get_file()
return tempdir
#looks at all files in a given level, and combines them into new or existing folders at the same level
def reorganize_subfolders(fpath):
for root, dirs, files in os.walk(fpath):
for file in files:
incorrect = False
#ignore files that end any of the ignored file types
for a in IGNORE_LIST:
if file.endswith(a):
incorrect = True
nName = file.split("_")
nName = nName[0:4]
#if any part of the string does not contain any of the correct information
for a in nName:
if a == "" or a == " ":
incorrect = True
if incorrect == False:
nName = '_'.join(nName)
#see if folder exists at this level or the file is already in correct directory
if nName not in root:
dirPath = os.path.join(root, nName)
if not os.path.exists(dirPath):
os.makedirs(dirPath)
os.rename(os.path.join(root, file), os.path.join(root, nName, file))
def main():
fpath = get_filepath()
reorganize_subfolders(fpath)
main()