python - Download under user's profile directory -


I have a hard time keeping that file, which I downloaded from inside the script to another folder. It will not make any difference but I am trying to update some programs remotely. I am able to download the file, but only in the folder inside the script. I need to run nininte.exe after downloading some command line arguments (i.e. silent), which I was going to pass this batch script I just would like to dump it into the download folder. When I hit it on Google installing Python in a specific folder.

Here is my code

  import urlib ninite = urllib.urlopen ("www DownloadSite.com") localFile = open ('ninite.exe', ' Wb ') localFile.write (ninite.read ()) ninite.close ()   

The script works very well but when I open the folder location localfile = (' % Userprofile% / downloads / ninite ',' wb ') then it returns an error that there is no file or directory with that file.

You can use environment to expand the variable such as % userprofile% < / Code> Use the directory name and file to download in the destination:

  #! / Usr / bin / env python Import OS import urllib url = "https://example.com/path" # where to get the file from dest_dir = os.path.expandvars ('% userprofile% / Downloads / ninite') file # Where to put # directory (repeater): Os.makedirs (dest_dir) except OSError: # unseen er rars pass # file urllib.urlretrieve (url, os.path.join (dest_dir, 'ninite.exe') ) Download    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -