0

When i exexute my python script .exe file, I want its shortcut or copy to go to a specific path of my drive using python code

I think that piece code should be like

def become_persistent():
    copied_file_location = os.environ["location"] + "\\ my scripts.exe"
    if not os.path.exists(copied_file_location):
        shutil.copyfile(sys.executable, copied_file_location)
zain
  • 19
  • 7
  • It's not clear what you're asking here. – Paul H May 25 '20 at 04:48
  • i want when my exe file is executed so a copy of my exe file goes to a specific drive my my pc – zain May 25 '20 at 04:52
  • Your python script is not an executable, so that's unclear. It's also unclear what you want to happen exactly. Assuming you package your script with something like PyInstaller, do you want to have the the executable move itself when it's executed? Why? – Grismar May 25 '20 at 04:56
  • i want this to understand the machinism .... mean when we install some software so a copy of their exe goes to appdata /startup . – zain May 25 '20 at 05:02
  • i have no answer of why am doing this to gain knowledge – zain May 25 '20 at 05:04

1 Answers1

0

Assumming you are using PyInstaller for making your script binary, here is how you determine path to exe file Determining application path in a Python EXE generated by pyInstaller The rest is simple - just copy that file to the directory you'd like to.

leotrubach
  • 1,509
  • 12
  • 15