• Coding

    Python Learning: Automate Boring Stuff with Python | Chapter 8 : My Solution to Project: Backing Up a Folder into a Zip File

    Just my solution to the project I found the solution to the project provided in the book really good, but it zipped the entire folder structure in the absolute path. Something I am not pleased with. By adding the filepath base name to the zipfile.Zipfile.write() function, after the absolute filepath (of the file to be written),  I was able to prevent that unecessary folder zipping.   Suggestions are welcomed!    [sourcecode language=”python” wraplines=”false”] #Backs up given file in a zip file and numbers accordingly #Usage: python backupzip <filepath> import sys, os, re, zipfile #TODO: get filepath if len( sys.argv ) == 2: filepath = sys.argv[1] filepath = os.path.abspath(filepath) #TODO: check…

  • Coding

    Python Learning: Automate Boring Stuff with Python | Making a directory and moving files into it

    With this script we can make a new directory(if it does not exist) and move files with a given ending into the directory. This was not a task in the book, but just something I thought of solving. Quite interesting to know what you could do with string operations like “startWith” and “endWith”. [sourcecode language=”python” wraplines=”false” collapse=”false”] #creates new directory and moves python script files into the newly created directory #Usage python mvdir.py <ending> <source> <destination> <except> import os, sys, shutil #TODO: GET ENDING AND DESTINATION STRINGS if len( sys.argv ) >= 4: ending = sys.argv[1] source = sys.argv[2] destination = sys.argv[3] destination = os.path.abspath(destination) source = os.path.abspath(source) exception =…

error: Content is protected !!