AnsweredAssumed Answered

python script to search for files and delete in multiple locations

Question asked by FPCWA_GISadmin on May 8, 2020
Latest reply on May 11, 2020 by FPCWA_GISadmin

I'm a beginner in python so know that it's very unlikely that this can't be done, but I don't have the skill (or time ) to devote to trying to figure this out unfortunately. I'm hoping somewhere here can. 

 

I'm setting up a batch file that will replicate all files and folders at 4 different offices to each other. This will ensure that each day, changes made in other locations are mirrored at each other location. The downside of this is, if someone wants to delete a folder or file, this process will just recreate it again based on the other sources. 

 

My thoughts are that I could create a "Files to Delete" folder at each site that is excluded from the mirror process, and then staff can move files/folders they want deleted into the "Files to Delete" folder. Before the mirror batch file runs, a python script could run which would search/list each file/folder inside "Files to Delete" and then search for that in the main folder structure (regardless of position) and delete it. Once it has been removed from all the sites, then the mirror process could run and it would not be recreated elsewhere again. 

 

I know it sounds clunky, so if someone has a better suggestion, I'm open to that too! 

 

I found this webpage, but don't have the time available to spend trying and trying and trying until I get somewhere with looming deadlines

 

 

batch file example below;

robocopy "C:\temp\Sync test\Manjimup" "C:\temp\Sync test\Bunbury" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Manjimup\Files to Delete"
robocopy "C:\temp\Sync test\Manjimup" "C:\temp\Sync test\Harvey" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Manjimup\Files to Delete"
robocopy "C:\temp\Sync test\Manjimup" "C:\temp\Sync test\Nannup" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Manjimup\Files to Delete"

 

robocopy "C:\temp\Sync test\Harvey" "C:\temp\Sync test\Bunbury" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Harvey\Files to Delete"
robocopy "C:\temp\Sync test\Harvey" "C:\temp\Sync test\Manjimup" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Harvey\Files to Delete"
robocopy "C:\temp\Sync test\Harvey" "C:\temp\Sync test\Nannup" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Harvey\Files to Delete"

 

robocopy "C:\temp\Sync test\Nannup" "C:\temp\Sync test\Bunbury" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Nannup\Files to Delete"
robocopy "C:\temp\Sync test\Nannup" "C:\temp\Sync test\Harvey" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Nannup\Files to Delete"
robocopy "C:\temp\Sync test\Nannup" "C:\temp\Sync test\Manjimup" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Nannup\Files to Delete"

 

robocopy "C:\temp\Sync test\Bunbury" "C:\temp\Sync test\Harvey" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Bunbury\Files to Delete"
robocopy "C:\temp\Sync test\Bunbury" "C:\temp\Sync test\Manjimup" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Bunbury\Files to Delete"
robocopy "C:\temp\Sync test\Bunbury" "C:\temp\Sync test\Nannup" /e /XO /dst /fft /xj /r:0 /XD "C:\temp\Sync test\Bunbury\Files to Delete"

Outcomes