0

I have some pre-made files that is kept in the same directory as the python script, I want to copy those into the target directory when I run the script.

I don't want to hardcode the path, especially if the script folder is moved to around. How do you get the script's directory path?

import shutil
import os

file_name = "example.txt"
source_file = '/'.join([this_should_be_script_directory, file_name])
current_dir = '/'.join([os.getcwd(), file_name])

shutil.copy(source_file, current_dir)
jellene
  • 409
  • 3
  • 9

0 Answers0