Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- foundfilenames = []
- printednames = []
- duplicatefiles = []
- def isfilefound( filename ):
- global foundfilenames
- for name in foundfilenames:
- if name == filename:
- return True
- return False
- def isfileprinted( filename ):
- global printednames
- for name in printednames:
- if name == filename:
- return True
- return False
- input( "This program will find all your duplicate files in a specified folder which you have told it to search. Press enter to begin!" )
- print( "***Never run this program on the partition which you have Windows installed on***" )
- print( "--------------------------------" )
- directory = input( "Which directory? : " )
- print( "--------------------------------" )
- whichfile = input( "Where would you like to save the duplicates-list document? (name full path + *.txt) : " )
- writefile = open(( whichfile ), 'w' )
- writefile.write( "These are the duplicates found in your specified path.\r\n\r\n" )
- for root, dirs, files in os.walk(directory):
- for name in files:
- filename = os.path.join(root, name)
- if isfilefound( name ):
- if not isfileprinted( name ):
- writefile.write( name + '\r\n' )
- printednames.append( name )
- duplicatefiles.append( filename )
- else:
- foundfilenames.append( name )
- writefile.close()
- for filename in duplicatefiles:
- if filename.count() > 0:
- writefile = open(( whichfile ), 'r' )
- readfile = writefile.read()
- print( readfile )
- print( "--------------------------------" )
- question = input( "Would you like to remove the duplicates? (yes/no) : ")
- print( "--------------------------------" )
- if question == 'yes':
- for filename in duplicatefiles:
- os.remove( filename )
- else:
- print( "Duplicates will not be removed. Check the document where you chose to save the list of duplicates" )
- else:
- break
- writefile.close()
- #if len( duplicatefiles ) == 0:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement