-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.py
More file actions
29 lines (23 loc) · 1.2 KB
/
task2.py
File metadata and controls
29 lines (23 loc) · 1.2 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
import shutil
import os
import csv
def create_dir(dir_name: str) -> str:
'''This function create dir where we must copy our dataset'''
if not os.path.isdir(dir_name):
os.mkdir(dir_name)
return dir_name
def create_copy_dataset(dir_copy: str, annotation_name: str) -> None:
'''This function copy our dataset in another directory and create csv file with 2 parameters: filename and file's class name'''
create_dir(dir_copy)
for dataset_item in os.listdir("dataset"):
files_list = os.listdir(os.path.join("dataset", dataset_item))
for file_name in files_list:
shutil.copy(os.path.join(os.path.join("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", encoding="UTF-16", 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(dir_copy: str, annotation_name: str) -> None:
''' This function call previous to run it in main'''
create_copy_dataset(dir_copy, annotation_name)