User:Python
Revision as of 23:46, 14 March 2014 by AlexJ (talk | contribs) (AlexJ moved page User:AlexJ to User:Python)
- ESERCIZIO 3 ESAME 20 GIUGNO 2013
- Scrivere un programma python o uno script bash per cercare all'interno
- della directory corrente tutti i file che abbiano lo stesso contenuto
import os,sys
import filecmp
def ordina(A,B):
for i in range(0,len(B)) : for j in range(i,len(B)) : if(B[i]>B[j]) : A[i],A[j]=A[j],A[i] B[i],B[j]=B[j],B[i] return A,B
def main() :
A=[] B=[] l=[] H={} P=[] print os.getcwd() pa=os.getcwd() for root, dirs, files in os.walk(pa): if(root != pa): H[root]=0 for root, dirs, files in os.walk(pa): if (root == pa) : for name in files : f = pa + '/' + name A = os.listdir(pa)
P = H.keys() for i in A : f = pa + '/' + i c = f in P if(c == 1) : A.remove(i) x=-1 for root, dirs, files in os.walk(pa): if (root == pa) : for name in files : c = name in A if(c == 1) : x=x+1 statinfo = os.stat(name) B.insert(x,statinfo.st_size) print l=list() (A,B)=ordina(A,B) j=1 c=0 z=0 for i in range(0,(len(A)-1)) : if(B[i] == B[j]) : F1 = open(A[i],'r') F2 = open(A[j],'r') if(filecmp.cmp(A[i], A[j])) : c=1 if(z==0): l.append(A[i]) z=1 l.append(A[j]) if (B[i] != B[j] and c==1): print "Questi file sono uguali di dimensione : ",B[i], "Byte" print l l=[] c=0 z=0 print j=j+1 if(c==1) : print "Questi file sono uguali di dimensione : ",B[i] print l print
if __name__ == "__main__" :
main()