Sep-21-2020, 01:04 PM
Python version used is 3.5.3
Python file is executed on OS Debian 9.11
This script checks if files in 'source folder' are already in 'destination folder'.
If not, move it to 'destination folder'.
Else, move it to 'duplicate folder'.
Files in SRC_PATH are physicaly on a Windows machine.
When i execute the script once, path.exists returns False.
When i execute the script a second time, path.exists returns True.
When I copy and paste the files from DEST_PATH to SRC_PATH and delete them from DEST_PATH and execute the script, path.exists returns False.
However, when i cut the files from DEST_PATH and paste it back to SRC_PATH (and DEST_PATH is thus empty), path.exists still returns True. Why?
Same when I "drag and drop" from DEST_PATH to SRC_PATH.
Someone has an idea about this mystery?
thx
Python file is executed on OS Debian 9.11
This script checks if files in 'source folder' are already in 'destination folder'.
If not, move it to 'destination folder'.
Else, move it to 'duplicate folder'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/usr/bin/env python3 import os import os.path from os import path SRC_PATH = "/mnt/fsdata/IT/Servers/PostGres/CDR" DEST_PATH = SRC_PATH + "/procd" DUP_PATH = SRC_PATH + "/dup" # r=root, d=directories, f = files for r, d, f in os.walk(SRC_PATH): for file in f: filePathName = r + "/" + file # check if file already exists in /procd folder: if path.exists(DEST_PATH + "/" + file ): print ( 'file exists' ) os.rename(filePathName, DUP_PATH + "/" + file ) continue # move file os.rename(filePathName, DEST_PATH + "/" + file ) break |
When i execute the script once, path.exists returns False.
When i execute the script a second time, path.exists returns True.
When I copy and paste the files from DEST_PATH to SRC_PATH and delete them from DEST_PATH and execute the script, path.exists returns False.
However, when i cut the files from DEST_PATH and paste it back to SRC_PATH (and DEST_PATH is thus empty), path.exists still returns True. Why?
Same when I "drag and drop" from DEST_PATH to SRC_PATH.
Someone has an idea about this mystery?
thx