I'm obviously doing something very wrong. I'd like to find files, that are in one directory but not in second directory (for instance xxx.phn in one directory and xxx.wav in second directory...
IT seems that I cannot detect, when file is NOT present in second directory (it's always showing like all files are)... I don't get any file displayed, although they exist...
import shutil, random, os, sys
if len(sys.argv) < 4:
print """usage: python del_orphans_dir1_dir2.py source_folder source_ext dest_folder dest_ext
"""
sys.exit(-1)
folder = sys.argv[1]
ext = sys.argv[2]
dest_folder = sys.argv[3]
dest_ext = sys.argv[4]
i = 0
for d, ds, fs in os.walk(folder):
for fname in fs:
basename = os.path.splitext(fname)[0]
if (not os.path.exists(dest_folder+'/'+basename + '.' + dest_ext) ):
print str(i)+': No duplicate for: '+fname
i=i+1
print str(i)+' files found'
str(i)call. Just doprint i, " files found". Andi+=1rather thani=i+1works.os.path.existsdoesn't work correctly, why do you need more than one or two lines to demonstrate same? Having the extra code just creates other places (not related toos.path.exists) the bug could hide.exists()call means that there could be a subtle difference between them. Ideally, a question like this would showls -lon the output from the print showing the file to exist, and an error message from the script showing it not to, and would use a variable assigned only once for both the print call and theexists()call, to avoid any chance of such bugs.print sys.argv[1:], and alsofor x in os.walk(path): print xfor bothfolderanddest_folder. (You might want to try setting up some test folders with only a few files in before doing this, though).