Python-Trying to make a file witho os in directory, no errors but the file won't appear

56 Views Asked by At

I want to create a txt file in appdata/roaming/Helloworld with os method. The file is my_file.txt and when I launch the programm, there is no error and python says that the file and the folder exists (os.path.exists(file_path) returns True) but when I go to my %AppData% folder (AppData/roaming), there is no folder named Helloworld.

here is the code:

directory = os.path.join(os.getenv('APPDATA'), 'Helloworld')
if not os.path.exists(directory):
    os.makedirs(directory)
file_path = os.path.join(directory, 'my_file.txt')
if not os.path.exists(file_path):
    with open(file_path, 'w') as f:
        f.write('Hello World!')

I tryed os.makedirs(directory, exist_ok=True) and it didn't work better.

0

There are 0 best solutions below