Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. foundfilenames = []
  5. printednames = []
  6. duplicatefiles = []
  7.  
  8. def isfilefound( filename ):
  9.    global foundfilenames
  10.    for name in foundfilenames:
  11.       if name == filename:
  12.          return True
  13.    return False
  14.  
  15. def isfileprinted( filename ):
  16.    global printednames
  17.    for name in printednames:
  18.       if name == filename:
  19.          return True
  20.    return False
  21.  
  22. input( "This program will find all your duplicate files in a specified folder which you have told it to search. Press enter to begin!" )
  23. print( "***Never run this program on the partition which you have Windows installed on***" )
  24. print( "--------------------------------" )
  25. directory = input( "Which directory? : " )
  26. print( "--------------------------------" )
  27. whichfile = input( "Where would you like to save the duplicates-list document? (name full path + *.txt) : " )
  28. writefile = open(( whichfile ), 'w' )
  29. writefile.write( "These are the duplicates found in your specified path.\r\n\r\n" )
  30.  
  31. for root, dirs, files in os.walk(directory):
  32.    for name in files:
  33.       filename = os.path.join(root, name)
  34.       if isfilefound( name ):
  35.          if not isfileprinted( name ):
  36.             writefile.write( name + '\r\n' )
  37.             printednames.append( name )
  38.          duplicatefiles.append( filename )
  39.       else:
  40.          foundfilenames.append( name )
  41.  
  42. writefile.close()
  43.  
  44. for filename in duplicatefiles:
  45.    if filename.count() > 0:
  46.       writefile = open(( whichfile ), 'r' )
  47.       readfile = writefile.read()
  48.       print( readfile )
  49.       print( "--------------------------------" )
  50.       question = input( "Would you like to remove the duplicates? (yes/no) : ")
  51.       print( "--------------------------------" )
  52.       if question == 'yes':
  53.          for filename in duplicatefiles:
  54.             os.remove( filename )
  55.       else:
  56.          print( "Duplicates will not be removed. Check the document where you chose to save the list of duplicates" )
  57.    else:
  58.       break
  59. writefile.close()
  60.  
  61. #if len( duplicatefiles ) == 0:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement