0

I'm writing a script that will download an executable from the internet, which will create more files. Now, if I download the file, it will be downloaded to the directory I told it, but when I open it using os.startfile(), it creates the files to the directory where the python script is located. How can I avoid that?

1
  • Move the file before opening it? So that the created files are in that directory Commented Oct 23, 2020 at 19:59

2 Answers 2

1

Either you can move the .py file to any other directory. or You can use os.chdir() to change the current working directory of the script during the runtime.

os.chdir('/path/to/directory')
Sign up to request clarification or add additional context in comments.

Comments

1

Do a os.chdir() before trying to run the executable:

os.chdir('<the target folder where you want the files to be created>')
...
os.startfile('<path to where the executable was downloaded>')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.