-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_teams.py
More file actions
72 lines (59 loc) · 3.58 KB
/
Copy pathsort_teams.py
File metadata and controls
72 lines (59 loc) · 3.58 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
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import shutil
def move_folders_by_numbers(parent_folder, target_folder, bib_list):
"""
Move folders with specific names (from numbers_list) from parent_folder to target_folder.
Args:
parent_folder (str): The path to the folder containing subfolders to check.
target_folder (str): The path to the folder where matching folders will be moved.
numbers_list (list of int): List of numbers. Folders with these names will be moved.
"""
# Ensure the target folder exists
for team in bib_list:
os.makedirs(os.path.join(target_folder, team[0]), exist_ok=True)
# Convert numbers_list to string for comparison
numbers_set = list(map(lambda x: [x[0], list(map(lambda y: "bib"+str(y), x[1]))], bib_list))
# Iterate through subfolders in the parent folder
for folder_name in os.listdir(parent_folder):
folder_path = os.path.join(parent_folder, folder_name)
if os.path.isdir(folder_path):
for team in numbers_set:
if folder_name in team[1]:
target_team_path = os.path.join(target_folder, team[0])
target_path = os.path.join(target_team_path, folder_name)
# Ensure the target team folder exists
os.makedirs(target_team_path, exist_ok=True)
if os.path.exists(target_path):
print(f"Folder {folder_name} already exists in {target_team_path}. Adding files to the existing folder.")
for file_name in os.listdir(folder_path):
src_file = os.path.join(folder_path, file_name)
dest_file = os.path.join(target_path, file_name)
# If the file already exists in the target, skip or overwrite based on your requirement
if os.path.exists(dest_file):
print(f"File {file_name} already exists in {target_path}. Skipping.")
else:
shutil.move(src_file, dest_file)
# Optionally, remove the now-empty source folder
if not os.listdir(folder_path):
os.rmdir(folder_path)
else:
print(f"Moving folder {folder_name} to {target_team_path}")
shutil.move(folder_path, target_path)
# Example usage
parent_folder = "sugarloafSl"
target_folder = "sugarloafSlTeams"
teams = [["BC", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 137]],
["Tufts", [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111]],
["UNH", [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]],
["SLU", [30, 31, 32, 33, 34, 35, 36, 37, 38, 39]],
["Dartmouth", [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 140, 141, 143]],
["BU", [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]],
["WPI", [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 161, 162, 163, 164, 165, 166, 167, 168, 169]],
["UVM", [70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 170, 177, 171, 172, 173, 174, 175, 176, 177, 178, 179, 104, 102]],
["Holy Cross", [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 180, 182, 181, 184, 187, 101]],
["NEU", [90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 156, 188, 189, 190, 191]]
["SLU", [101, 102, 103, 104, 105, 106, 107, 108, 109]]
]
# teams = [["neu", [111, 127, 139, 156, 6, 35, 45, 57, 84]]]
if __name__ == "__main__":
move_folders_by_numbers(parent_folder, target_folder, teams)