Select to view content in your preferred language

python script to search for files and delete in multiple locations

1013
2
05-08-2020 12:59 AM
FPCWAGIS_Admin
Occasional Contributor

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"

Tags (1)
0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

Hi, I would love to live in a place called Manjimup! Don't care what it's like, just saying the name will do me fine.

I'm guessing each town's edits are isolated to their own folders? i.e. there's no shared edits and you only want to replicate each location's data to share between you? I'm guessing a county which is managing districts etc?

0 Kudos
FPCWAGIS_Admin
Occasional Contributor

The staff are generally based out of one of those 4 offices, but tend to move around from time to time and still need access to the data that they are generating. Unfortunately, web line speeds stop us accessing it directly over the web from their home office, so we're trying to make the data replicate out overnight so that if they are in a different office the next day, then latest version of each file is also in that location. They can then open, edit and save, and when they go back to their home office, the latest version will have been copied back as well. In essence, the latest version is always retained. It's unlikely that staff would edit the same files on the same day in different locations, so hopefully conflicts won't be an issue (not ideal I know). 

As for Manjimup, it's a great little town in the SW of Western Australia. https://www.manjimupwa.com/

0 Kudos