Sometimes we need to find the duplicate files in our file system, or inside a specific folder. In this tutorial we are going to code a Python script to do this. This script works in Python 3.x. The program is going to receive a folder or a list of folders to scan, then is going [...]
Category: Cookbook Recipes
Popular Python cookbook recipes – small Python programs, with example code samples to get you started on the language, and give you in-depth knowledge.
How to Move/Copy a File or Directory (Folder) with a Progress Bar in Python
In the last article, titled How to Recursively Copy a Folder (Directory) in Python, I covered how to copy a folder recursively from one place to another. As useful as that is, there is still something else that we could add that would make copying a directory much more user friendly! Enter the progress bar [...]
Recursive File and Directory Manipulation in Python (Part 3)
In Part 2 of this series we expanded our file-searching script to be able to search for multiple file extensions under a tree, and to write the results (all paths to files of matching extensions found) to a log file. Now that we’ve come to the final part of the series, we’ll add more functionality [...]
Recursive File and Directory Manipulation in Python (Part 2)
In Part 1 we looked at how to use the os.path.walk and os.walk methods to find and list files of a certain extension under a directory tree. The former function is only present in the Python 2.x, and the latter is available in both Python 2.x and Python 3.x. As we saw in the previous [...]
Recursive File and Directory Manipulation in Python (Part 1)
If you are looking to utilize Python to manipulate your directory tree or files on your system, there are many tools to help, including Python’s standard os module. The following is a simple/basic recipe to assist with finding certain files on your system by file extension. If you have had the experience of “losing” a [...]
Watermark your Images in Python 2.x
When you take photographs and post it onto the internet, it is often handy adding a watermark to prevent and discourage unauthorized copies or image theft. Below is a simple Python script that uses the PIL module to watermark your images. It adds a visible text watermark to the image using the system font. We [...]
Recursive Python Function Example: Make a List of Your Movies!
So. What’s better than making a list of video files on your hard disc drive? Let’s make a list of all video filesĀ in a folder, and all other folders in it! What is a Recursive Python Function? Recursion is a concept in computer science. Essentially, it divides a problem into sub-problems. Recursion in Python generally [...]
Python Beautiful Soup Example: Yahoo Finance Scraper
Python offers a lot of powerful and easy to use tools for scraping websites. One of Python’s useful modules to scrape websites is known as Beautiful Soup. In this example we’ll provide you with a Beautiful Soup example, known as a ‘web scraper’. This will get data from a Yahoo Finance page about stock options. [...]
Resize an Image with Python 2.x (and in Batch)
Python is a very powerful scripting language and you will be pleasantly surprised to find that a lot of the common functions you would want to build are available to you in library form. The Python ecosystem is very alive and full of libraries. Point in case, today I will show you how to easily [...]