Jump to content

[Python] MD5 de todos os ficheiros da directoria, e sub directorias


newbeen
 Share

Recommended Posts

Deixem aí ajudas para métodos melhorias vou precisar disto para um projecto meu em desenvolvimento.....


import os, md5, tkFileDialog

#######################################
#### GetMd5 by Newbeen beta relase  ###
#### -----------------------------  ###
#### |  ToDo: comparar md5 de 2   | ###
#### |  ficheiros, corregir bug   | ###
#### |  quando um ficheiro esta   | ###
#### |  em uso  pára execucao...  | ###
#### |____________________________| ###
#######################################

class GetMd5:

   def listfiles(self, arg, dirname, names):
           flist=open("listfile.txt", "a")
           for name in names:
           afile=os.path.join(dirname, name)
           if os.path.isfile(afile):
               hashmd5=file(afile ,'rb')
               md5_file=md5.new(hashmd5.read()).digest().encode('hex')
               flist.write(afile+'\t'+md5_file+'\n')
               print afile+"\t is file md5 --> "+md5_file
           else:
               flist.write(afile+'\n')
               print afile+"\t directiry"
       print "\n"
       flist.close()



md=GetMd5()
dire=tkFileDialog.askdirectory()#corrigir bug fazer desaparecer janela!!!
os.path.walk(dire, md.listfiles, None)

raw_input('Prima Qualquer tecla para sair resultado no listfile.txt')

Abraços!

RHCE - 120-062-534

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.