I'm trying to create a python script (with very limited knowledge) that will create a text document on the desktop of whoever runs the program. The section I have that should actually create the text file looks like so:
save_path = 'Desktop'
name_of_file = "examplefile"
completeName = os.path.join(save_path, name_of_file+".txt")
file1 = open(completeName, "w+")
toFile = '''text'''
file1.write(toFile)
file1.close()
Everything works as intended when run in Visual Studio Code, but when run in CMD, I get the error:
File "file.py", line 101, in <module>
open(completeName, "w+")
FileNotFoundError: [Errno 2] No such file or directory: 'Desktop\\examplefile.txt'
When run in py.exe, it simply crashes.
I've used C:\Users\MyName\Desktop>py file.py
and C:\Users\MyName\Desktop>python3 file.py
to execute the script and had the same error, which I guess doesn't surprise me.
I've looked online quite a bit on how to solve this, but pretty much everything I've seen just restates using open(filename, "w+")
to create a text file (which I already know) or is in regards to using PATH, which I don't think I need, but admittedly is not something I understand that well.
To summarize, I cannot figure out for the life of me why the script works exclusively in VS Code.