Skip to content
Snippets Groups Projects
Commit 6c8a09e1 authored by Valtteri Ingman's avatar Valtteri Ingman
Browse files

siirtää valitun joukon tiedostoja jokaiseen opiskelijan kansioon.

parent 129ff4db
No related branches found
No related tags found
No related merge requests found
import os
import shutil
# Function to find folders with "_" in their names in the current working directory
def find_folders_with_underscore():
cwd = os.getcwd()
folders_with_underscore = []
for item in os.listdir(cwd):
item_path = os.path.join(cwd, item)
if os.path.isdir(item_path) and "_" in item:
folders_with_underscore.append(item_path)
return folders_with_underscore
# Modified function to search for a file in each folder and copy a list of files if found
def copy_files_to_all_found_locations(folder_paths, file_to_find, files_to_copy):
cwd = os.getcwd()
for folder in folder_paths:
target_file_path = os.path.join(folder, file_to_find)
# Check if the target file exists in the folder
if os.path.exists(target_file_path):
print(f"Found {file_to_find} in {folder}. Copying files...")
# Attempt to copy each file in the files_to_copy list
for file in files_to_copy:
source_file_path = os.path.join(cwd, file)
if os.path.exists(source_file_path):
shutil.copy(source_file_path, folder)
print(f"Copied {file} to {folder}")
else:
print(f"File {file} does not exist in the current working directory. Cannot copy.")
# List of files to copy
files_to_copy = ["input.txt", "autorunner.py"]
# Example usage
if __name__ == "__main__":
folders_with_underscore = find_folders_with_underscore()
print(folders_with_underscore)
copy_files_to_all_found_locations(folders_with_underscore, "VerkkokauppaUI.java", files_to_copy)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment