I've written the below
url='http://lle.gov.wales/catalogue/item/TraditionalOrchards.zip'
wget.download(url, '/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/TraditionalOrchards.zip')
file_name = "/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/TraditionalOrchards.zip"
with ZipFile(file_name, 'r') as zip:
zip.printdir()
zip.extractall('/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped')
old_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/TRADITIONAL_ORCHARDSPolygon.shp"
new_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/traditional_orchardspolygon.shp"
os.rename(old_name, new_name)
old_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/TRADITIONAL_ORCHARDSPolygon.dbf"
new_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/traditional_orchardspolygon.dbf"
os.rename(old_name, new_name)
old_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/TRADITIONAL_ORCHARDSPolygon.prj"
new_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/traditional_orchardspolygon.prj"
os.rename(old_name, new_name)
old_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/TRADITIONAL_ORCHARDSPolygon.shx"
new_name = r"C:/Users/DylanContet/Desktop/AutomationProject/LayerListFiles/60/Unzipped/traditional_orchardspolygon.shx"
os.rename(old_name, new_name)
as a way to download a zipfile, unzip it and rename the specific files (like .shp, .prj, etc.).
Is there a way to use Python to read a txt file to open a link in that txt file, then to use a specified name on the txt file to rename all the files in that ZIP?
So for example it will look like the following in the .txt
url_to_website new_name_for_files
url_to_website_2 new_name_for_files_2
I'd like it to go line by line and download then with the url then rename with the new name next to the URL.
I can do it 1 file at a time as shown above but I've got over 300 files to download and rename.