kashin_maxim_lab_2 #31

Merged
Alexey merged 5 commits from kashin_maxim_lab_2 into main 2024-10-07 23:00:06 +04:00
2 changed files with 11 additions and 4 deletions
Showing only changes of commit 6ce78e60ad - Show all commits

View File

@ -4,4 +4,4 @@ services:
build:
context: ./program_0
volumes:
- ./data:/var/data
- ./var/data:/data

View File

@ -1,11 +1,12 @@
import random
import os
folder_path = './kashin_maxim_lab_2/var/data'
folder_path = '/data'
def creat_folder():
if not os.path.exists(folder_path):
os.makedirs(folder_path)
print(f"Папка `{folder_path}` создана!")
else:
print(f"Папка `{folder_path}` уже существует!")
@ -15,23 +16,29 @@ def delete_files_in_folder():
try:
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Файл `{file_path}` удален.")
except Exception as e:
print(f'Ошибка при удалении файла {file_path}. {e}')
def creat_file():
for i in range(random.randrange(10, 20)):
file = open(f'{folder_path}/file_{i}.txt', 'w+')
print(f"Создан файл: {folder_path}/file_{i}.txt")
for i in range(random.randrange(10, 50)):
file.write(f'{create_lines()} \n')
file.close()
def create_lines():
lines = [i for i in range(random.randrange(1, 50),random.randrange(50, 100),random.randrange(1, 10))]
lines = [i for i in range(random.randrange(1, 50), random.randrange(50, 100), random.randrange(1, 10))]
return lines
if os.path.exists(folder_path):
print(f"Папка `{folder_path}` существует, удаляем старые файлы...")
delete_files_in_folder()
creat_file()
else:
print(f"Папка `{folder_path}` не существует, создаем...")
creat_folder()
creat_file()
creat_file()
print("Скрипт на создание файлов выполнен.")