Si votre email correspond à un compte, vous recevrez un lien de réinitialisation.
Bonsoir !La fonction ci-dessous retourne, très vite, contenu et taille d'unsous-répertoire (récursivement en option) ; sous Win, bien sûr.@-salutations--Michel Claveau#----------debut------------------------------------------------import win32filedef dirfast(path, recursifúlse):"""Michel Claveau InformatiqueTrouve très vite contenu et taille d'un dossierIgnore ('saute') . et ..Retourne :taille totalenb fichiernb sous-dossiersliste_fichiersliste_path_des_fichiersliste_sous-dossiersliste_path_des_sous-dossiers"""try:items = win32file.FindFilesW(path + "*")except win32file.error, details:self.errors[path] = str(details[-1])returnfichiers=[]fpath=[]srep=[]srpath=[]fdatime=[]fsize=[]totalsize = 0nbfichiers = 0nbsousrep = 0for item in items:#print item#attr = item[0]#datetime = item[1]size = item[-5]name = item[-2]if item[0] & 16:if name != "." and name != "..":srep.append(name)srpath.append(path)nbsousrep += 1if recursif:tempsize,tempnbfichiers,tempnbsousrep,tempfichiers,tempfpath,tempsrep,tempsrpath= dirfast(path+''+name,recursif)totalsize += tempsizenbfichiers += tempnbfichiersnbsousrep += tempnbsousrepfichiers.extend(tempfichiers)fpath.extend(tempfpath)srep.extend(tempsrep)srpath.extend(tempsrpath)else:fichiers.append(name)fpath.append(path)fdatime.append(item[1])fsize.append(item[5])totalsize += sizenbfichiers += 1return totalsize,nbfichiers,nbsousrep,fichiers,fpath,srep,srpathif __name__ == "__main__":tai,nbf,nbs,fl,fp,sl,sp=dirfast(r"D:Dev", recursif=True) #==>indiquer le bon dossierprint '-'*55print 'Dossier:',fp[0]printprint ' Taille :',taiprint ' Nb Fichiers :',nbfprint ' Nb Sous-dirs:',nbsprint '-'*55#----------fin--------------------------------------------------
Bonsoir ! La fonction ci-dessous retourne, très vite, contenu et taille d'un sous-répertoire (récursivement en option) ; sous Win, bien sûr. @-salutations -- Michel Claveau #----------debut------------------------------------------------ import win32file def dirfast(path, recursifúlse): """Michel Claveau Informatique Trouve très vite contenu et taille d'un dossier Ignore ('saute') . et .. Retourne : taille totale nb fichier nb sous-dossiers liste_fichiers liste_path_des_fichiers liste_sous-dossiers liste_path_des_sous-dossiers """ try: items = win32file.FindFilesW(path + "\*") except win32file.error, details: self.errors[path] = str(details[-1]) return fichiers=[] fpath=[] srep=[] srpath=[] fdatime=[] fsize=[] totalsize = 0 nbfichiers = 0 nbsousrep = 0 for item in items: #print item #attr = item[0] #datetime = item[1] size = item[-5] name = item[-2] if item[0] & 16: if name != "." and name != "..": srep.append(name) srpath.append(path) nbsousrep += 1 if recursif: tempsize,tempnbfichiers,tempnbsousrep,tempfichiers,tempfpath,tempsrep,tempsrpath = dirfast(path+'\'+name,recursif) totalsize += tempsize nbfichiers += tempnbfichiers nbsousrep += tempnbsousrep fichiers.extend(tempfichiers) fpath.extend(tempfpath) srep.extend(tempsrep) srpath.extend(tempsrpath) else: fichiers.append(name) fpath.append(path) fdatime.append(item[1]) fsize.append(item[5]) totalsize += size nbfichiers += 1 return totalsize,nbfichiers,nbsousrep,fichiers,fpath,srep,srpath if __name__ == "__main__": tai,nbf,nbs,fl,fp,sl,sp=dirfast(r"D:Dev", recursif=True) #==> indiquer le bon dossier print '-'*55 print 'Dossier:',fp[0] print print ' Taille :',tai print ' Nb Fichiers :',nbf print ' Nb Sous-dirs:',nbs print '-'*55 #----------fin--------------------------------------------------