Last active
July 22, 2021 12:45
-
-
Save CalK16/24479183d9774e28365cb643786bdbc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import shutil | |
import signal | |
import sys | |
############# Fill this Box ################### | |
# source_directory: folder which containers files to grab from | |
# target_directory: folder where to store files | |
# data_directory: you need to create a .txt file to record files | |
source_directory = "//vmware-host/Shared Folders/test" | |
target_directory = "C:/Users/flip/Desktop/private" | |
data_directory = "C:/Users/flip/Desktop/database.txt" | |
time_interval = 5 # seconds | |
############################################### | |
database = [] | |
# preprocessing | |
if os.path.lexists(source_directory) is False: | |
print("no such source directory") | |
exit(1) | |
if os.path.lexists(target_directory) is False: | |
print("no such target directory") | |
exit(1) | |
def signal_handler(sig, frame): | |
print('You pressed Ctrl+C!') | |
with open(data_directory, "w+") as f: | |
for file in database: | |
f.write(file + "\n") | |
sys.exit(0) | |
signal.signal(signal.SIGINT, signal_handler) | |
with open(data_directory, 'r') as f: | |
database = f.read().splitlines() | |
print(database) | |
while True: | |
files = os.scandir(path=source_directory) | |
for file in files: | |
if file.name in database or file.is_dir(): | |
continue | |
shutil.move(file.path, target_directory) | |
database.append(file.name) | |
time.sleep(time_interval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment