Need Help
Get input for where the file is located & tell the new directory to save downloaded URLs to filepath variable assumes the text document with links is in the location of the python script - while this works, I would also like this to change to direct.
import os.path
import urllib.request
# Get one line of text (e.g. C:\user\user\path\directory)
filepath = input('please input the url file path: ')
links = open('links.txt', 'r')
newpath = input('Where would you like to store the file? ')
for link in links:`
# then get the filename from the end of the URL
link = link.strip()
filename = link.rsplit('/', 1)[-1]
# Does this file exist in this folder? If not, download it
if not (os.path.isfile(filename)):
print ('Downloading: ' + filename + " to " + newpath)
try:
urllib.request.urlretrieve(link, newpath + filename)
print ("File size was", os.path.getsize(filename))
except Exception as inst:
print (inst)
print (' Encountered unknown error. Continuing.')
# File exists; don't download
else:
print("This file exists already.")
# End of program
print("Finished downloading."