Video Demo: https://youtu.be/769DdzG_GBw
This program implements a folder mirror. Every change that happens on the source folder will be mirrored to the replica folder while the program keeps running. Also, the changes will be logged in the terminal and in a specified log.txt file.
The program usage is pretty objective:
- Download project.py
- Setup the folders
- Execute the programm per the instructions below:
The programm must be executed followed by 4 parameters.
- Path to the folder you want to track.
- Path to where your replica folder is located.
- Path to where you want the log file to be created.
- Interval in seconds between each update. (Lower intervals and big source folder may decrease performance)
Example:
python mirror.py "C:\\path\\to\\source\\folder\\" "C:\\path\\to\\replica\\folder" "C:\\path\\to\\log\\file\\" "interval(seconds)"
python mirror.py "C:\\Users\\Miguel\\Desktop\\Demonstration\\Source Folder\\" "C:\\Users\\Miguel\\Desktop\\Demonstration\\Replica Folder\\" "C:\\Users\\Miguel\\Desktop\\Demonstration\\" 0.1
The main function is responsible for two things:
- Get user input and escaping it in the case there is a space in any of the folder paths.
- Execute the mirror function in the interval provided by the user.
The mirror function is the core of the programm. When called it will search for every file on the source folder, checking if it already exists in the replica folder.
Case it don't exists, mirror will create a copy of the respective file. Otherwise, it will check again, now looking for modifications. Since it is not possible to compare two folders directly, in the case that mirror confirm that some file is a folder, it will call itself to run through that folder.
Mirror is capable of keeping track of and handling:
- Folder creation/deletion
- Folder modification
- File creatio/deletion
- File modification
Mirror will raise and expection case is trying copy an entire app. Since it can't handle the installation proccess.
Log changes will automatically take care of writing the logs of every change made by mirror. It takes an action as key to formulate a string: For consistency, the action string should be an verb.
Check paths takes as many arguments as the user wants. Obs.: Check paths will raise an exception FileNotFoundError in case any of the arguments cannot be found in the OS.
The program currently has handling for invalid inputs. Such as files or folders not found.
Some actions that a user can take while running the app can cause it to raise an exception. Such as:
- Changing any of the file paths.
- Replica folder be the same as source folder.
- Moving installable apps.
- Moving files that should not be moved.