-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.py
More file actions
26 lines (20 loc) · 1.01 KB
/
task2.py
File metadata and controls
26 lines (20 loc) · 1.01 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
import shutil
import os
import csv
def create_dir(dir_name: str) -> str:
if not os.path.isdir(dir_name):
os.mkdir(dir_name)
return dir_name
def create_copy_dataset(dataset: str, dir_copy: str, annotation_name: str) -> None:
create_dir(dir_copy)
for dataset_item in os.listdir(os.path.join(dataset, "dataset")):
files_list = os.listdir(os.path.join(dataset, "dataset", dataset_item))
for file_name in files_list:
shutil.copy(os.path.join(os.path.join(dataset, "dataset", dataset_item),
file_name), os.path.join(dir_copy, f"{dataset_item}_{file_name}"))
with open(os.path.join(dir_copy, annotation_name), mode="a", newline='') as file:
file_writer = csv.writer(file, delimiter=",")
for file_name in files_list:
file_writer.writerow([f"{dataset_item}_{file_name}", dataset_item])
def run2(dataset: str, dir_copy: str, annotation_name: str) -> None:
create_copy_dataset(dataset, dir_copy, annotation_name)