I had to update a file in every folder in which I used my pybook app for taking notes and other sort of organizing stuffs. To avoid doing the update in every folder, I decided to make this script that copies the latest version in all the folders, having them named something_book (where something is a different name for different stuffs). So this is the code to save some time. I also made a .bat file tha makes me do it from the cmd wherever I am.
import os import shutil import glob book = glob.glob("G:\\python_book\\book2*.py")[-1].split("\\")[-1] folders = glob.glob("G:\\*_book") ind = folders.index("G:\\python_book") folders.pop(ind) folders = [x for x in folders if x != "python_book"] # folders += glob.glob("G:\\pymemo_*") print("Cartelle:") print(*folders, sep="\n") print() print("To copy:") print(book) print() for fold in folders: print(fold, book) shutil.copy("G:\\python_book\\" + book, fold)
Unzip a file in different folders
Whith this script I can unzip some files into different folders ending with _book
# Unzip the files in a zipped file in the same dir of this script import os import shutil import glob import zipfile def unzip(name): "Unzip zipped file" with zipfile.ZipFile(name, 'r') as zip_ref: zip_ref.extractall(".") def unzip_to_all(): "Shows the folders" folders = glob.glob("G:\\*_book") ind = folders.index("G:\\python_book") folders.pop(ind) print("Cartelle:") print(*folders, sep="\n") for fold in folders: os.chdir(fold) unzip("G:\\python_book\\book.zip") unzip_to_all()
Twitter: @pythonprogrammi - python_pygame