Swatcat
Swatcat

Reputation: 55

Python : Unable to compare two directories

I have two directories (below) that I am trying to compare

Left:

C:\Temp\Sync\GUI\config.xml
C:\Temp\Sync\GUI\jobs
C:\Temp\Sync\GUI\jobs\Add
C:\Temp\Sync\GUI\jobs\Add\builds
C:\Temp\Sync\GUI\jobs\Add\config.xml
C:\Temp\Sync\GUI\jobs\Add\builds\legacyIds
C:\Temp\Sync\Risk\jobs\TOP_Deriv_RiskAlgo\builds
C:\Temp\Sync\Risk\jobs\TOP_Deriv_RiskAlgo\config.xml
C:\Temp\Sync\Risk\jobs\TOP_Deriv_RiskAlgo\builds\legacyIds
C:\Temp\Sync\Risk\jobs\TOP_Deriv_RiskCare\builds
C:\Temp\Sync\Risk\jobs\TOP_Deriv_RiskCare\config.xml
C:\Temp\Sync\Risk\jobs\TOP_Deriv_RiskCare\builds\legacyIds

Right:

C:\Temp\tmptm4bod\GUI\config.xml
C:\Temp\tmptm4bod\GUI\jobs
C:\Temp\tmptm4bod\GUI\jobs\Add
C:\Temp\tmptm4bod\GUI\jobs\Add\builds
C:\Temp\tmptm4bod\GUI\jobs\Add\config.xml
C:\Temp\tmptm4bod\GUI\jobs\Add\builds\legacyIds
C:\Temp\tmptm4bod\Newfolder\config.xml
C:\Temp\tmptm4bod\Newfolder\jobs
C:\Temp\tmptm4bod\Newfolder\jobs\Deriv_Amend
C:\Temp\tmptm4bod\Newfolder\jobs\Deriv_Amend\builds
C:\Temp\tmptm4bod\Newfolder\jobs\Deriv_Amend\config.xml
C:\Temp\tmptm4bod\Newfolder\jobs\Deriv_Amend\builds\legacyId

When I do the comparison, the 'NewFolder' directory on the right is listed, but not the files within it, which I don't understand.

syncdStoredJobs =  os.path.join(workspace, "storedJobs")    
comparisonDiff = filecmp.dircmp(syncdStoredJobs, cleanJobsDir, [], []) 

Am I missing something?

Upvotes: 0

Views: 68

Answers (1)

mwchase
mwchase

Reputation: 811

According to the docs, dircmp will only recurse into common directories, and only if you tell it to.

If a subdirectory only exists on one side, then the same holds true for its contents.

It may be possible to build a utility function that uses a dircmp to do what you want. Basically just look for directories that only exist on one side, and walk them.

Upvotes: 1

Related Questions