<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fede</id>
	<title>Sistemi Operativi - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fede"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php/Special:Contributions/Fede"/>
	<updated>2026-05-15T00:28:37Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=517</id>
		<title>ProvaTeorica 2012.07.16</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=517"/>
		<updated>2014-03-28T16:58:16Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.cs.unibo.it/~renzo/so/compiti/2012-07-16.tot.pdf Link Testo]&lt;br /&gt;
&amp;lt;h2&amp;gt;Esercizio C.2&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mia Soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define RED 0&lt;br /&gt;
#define BLUE 1&lt;br /&gt;
//restituisce 1 se c'e piu del 75% blue o 75% di red&lt;br /&gt;
//restituisce 0 se non c'e una maggiornza&lt;br /&gt;
int media(color){&lt;br /&gt;
	int mediared;&lt;br /&gt;
	int localinto =  into;&lt;br /&gt;
	if (color != NULL){&lt;br /&gt;
		localinto[color]++;&lt;br /&gt;
	}&lt;br /&gt;
	mediared = ((100*localinto[0])/(localinto[0]+localinto[1]));&lt;br /&gt;
	if(mediared &amp;gt;=75 || mediared &amp;lt; 25){&lt;br /&gt;
		return 1;//75% di rossi o di blue&lt;br /&gt;
	}else{&lt;br /&gt;
		return 0;// non c'e maggioranza		&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
&lt;br /&gt;
	conditon oktoenter[2];&lt;br /&gt;
	int into[2];&lt;br /&gt;
&lt;br /&gt;
	enter(color){&lt;br /&gt;
		if(media(color) != 1){// attendo perche' non c'e una maggioranza&lt;br /&gt;
			oktoenter[color].wait();&lt;br /&gt;
		}&lt;br /&gt;
		into[color]++;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	exit(color){&lt;br /&gt;
		into[color]--;&lt;br /&gt;
		if(media(1-color) == 1){&lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
		}else if(media(color) == 1){&lt;br /&gt;
			oktoenter[color].signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
- Midolo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define ROSSO 0&lt;br /&gt;
#define BLU 1&lt;br /&gt;
&lt;br /&gt;
monitor limcol {&lt;br /&gt;
	condition oktoenter&lt;br /&gt;
	int running[2] // numero di processi rossi [0] e blu [1] in esecuzione&lt;br /&gt;
	queue waiting // coda dei colori dei processi in attesa&lt;br /&gt;
	&lt;br /&gt;
	/* restituisce true se aggiungendo un processo del colore passato viene rispettato il 75%&lt;br /&gt;
	dei processi di un colore */&lt;br /&gt;
	bool morethan75p(colore) { &lt;br /&gt;
		return (running[colore]+1&amp;gt;=running[1-colore]*3 || (running[colore]+1)*3&amp;lt;=running[1-colore])&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	// risveglia un processo del colore passato se è possibile farlo&lt;br /&gt;
	void checkwakeup() {&lt;br /&gt;
		if (waiting.empty() == false) {&lt;br /&gt;
			colore=waiting.head() // head resituisce l'elemento in testa senza rimuoverlo&lt;br /&gt;
			if (morethan75p(colore)) { &lt;br /&gt;
				waiting.dequeue()&lt;br /&gt;
				oktoenter.signal()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter(colore) {&lt;br /&gt;
		if (morethan75p(colore)==false) {&lt;br /&gt;
			waiting.enqueue(colore)&lt;br /&gt;
			oktoenter.wait()&lt;br /&gt;
		}&lt;br /&gt;
		running[colore]++&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit(colore) {&lt;br /&gt;
		running[colore]--&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* la politica FIFO impedisce che si verifichi starvation, perché nel caso pessimo un processo&lt;br /&gt;
che vuole entrare dovrà attendere fino a che tutti quelli in esecuzione terminino */&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Daniele Cortesi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
define RED 0&lt;br /&gt;
define BLUE 1&lt;br /&gt;
int majorcolor = -1&lt;br /&gt;
int numproc[2] = 0,0&lt;br /&gt;
cond oktoenter[2]  //bastavano due condizioni.&lt;br /&gt;
cond oktoexit[2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
	procedure entry enter(COL){&lt;br /&gt;
		if(COL == majorcolor){&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			if((proc[majorcolor]*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;lt; 75)&lt;br /&gt;
				oktoenter[COL].wait()&lt;br /&gt;
			if(majorcolor == -1)&lt;br /&gt;
				majorcolor == COL&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			majorcolor = COL&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit(COL){&lt;br /&gt;
		if(numproc[COL] + numproc[1-COL] == 1){&lt;br /&gt;
			majorcolor = -1&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == majorcolor){&lt;br /&gt;
			if(((proc[majorcolor] - 1)*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;lt; 75){&lt;br /&gt;
				oktoexit[COL].wait()&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoexit[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
define RED 0&lt;br /&gt;
define BLU 1&lt;br /&gt;
&lt;br /&gt;
limcol{&lt;br /&gt;
	/*variable*/&lt;br /&gt;
	int array[2] = 0,0;&lt;br /&gt;
	color major = -1;&lt;br /&gt;
	/*condition*/&lt;br /&gt;
	condition oktoenter[2];&lt;br /&gt;
	condition oktoleave[2];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter( color ){&lt;br /&gt;
		if ( majorcolor == -1 ) &lt;br /&gt;
			majorcolor = color;&lt;br /&gt;
		if ( majorcolor == (1-color) &amp;amp;&amp;amp; newmajorcolor%(color) &amp;lt; 75% )&lt;br /&gt;
			oktoenter[color].wait();&lt;br /&gt;
		array[color]++; &lt;br /&gt;
		if ( majorcolor == -1 )            //se un processo si risveglia nel monitor vuoto deve impostare majorcolor&lt;br /&gt;
			majorcolor = color;&lt;br /&gt;
		if ( newmajorcolor%(1-color) &amp;gt;= 75% )         &lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
					}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit( color ){&lt;br /&gt;
		if ( majorcolor == color &amp;amp;&amp;amp; majorcolor_less1%(color) &amp;gt; 75% )&lt;br /&gt;
			oktoleave[color].wait();&lt;br /&gt;
		array[color]--;&lt;br /&gt;
		if ( !colorsempty() )&lt;br /&gt;
			if ( majorcolor_less1%(color) &amp;gt;= 75% )&lt;br /&gt;
				oktoleave[1-color].signal();&lt;br /&gt;
		else{&lt;br /&gt;
			majorcolor == -1;&lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
				}&lt;br /&gt;
					}&lt;br /&gt;
		 &lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
newmajorcolor%(color) calcola la nuova % del colore maggiore aggiungendo color&lt;br /&gt;
majorcolor_less1%(color) calcola la nuova % del colore maggiore togliendo color&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Pir@t@&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=516</id>
		<title>ProvaTeorica 2012.07.16</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=516"/>
		<updated>2014-03-28T16:57:57Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.cs.unibo.it/~renzo/so/compiti/2012-07-16.tot.pdf Link Testo]&lt;br /&gt;
&amp;lt;h2&amp;gt;Esercizio C.2&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mia Soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define RED 0&lt;br /&gt;
#define BLUE 1&lt;br /&gt;
//restituisce 1 se c'e piu del 75% blue o 75% di red&lt;br /&gt;
//restituisce 0 se non c'e una maggiornza&lt;br /&gt;
int media(color){&lt;br /&gt;
	int mediared;&lt;br /&gt;
	int localinto =  into;&lt;br /&gt;
	if (color != NULL){&lt;br /&gt;
		localinto[color]++;&lt;br /&gt;
	}&lt;br /&gt;
	mediared = ((100*localinto[0])/(localinto[0]+localinto[1]));&lt;br /&gt;
	if(mediared &amp;gt;=75 || mediared &amp;lt; 25){&lt;br /&gt;
		return 1;//75% di rossi o di blue&lt;br /&gt;
	}else{&lt;br /&gt;
		return 0;// non c'e maggioranza		&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
&lt;br /&gt;
	conditon oktoenter[2];&lt;br /&gt;
	int into[2];&lt;br /&gt;
&lt;br /&gt;
	enter(color){&lt;br /&gt;
		if(media(color) != 1){// attendo perche' non c'e una maggioranza&lt;br /&gt;
			oktoenter[color].wait();&lt;br /&gt;
		}&lt;br /&gt;
		into[color]++;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	exit(color){&lt;br /&gt;
		into[color]--;&lt;br /&gt;
		if(media(1-color) == 1){&lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
		}else if(media(color) == 1){&lt;br /&gt;
			oktoenter[color].signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
- Midolo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define ROSSO 0&lt;br /&gt;
#define BLU 1&lt;br /&gt;
&lt;br /&gt;
monitor limcol {&lt;br /&gt;
	condition oktoenter&lt;br /&gt;
	int running[2] // numero di processi rossi [0] e blu [1] in esecuzione&lt;br /&gt;
	queue waiting // coda dei colori dei processi in attesa&lt;br /&gt;
	&lt;br /&gt;
	/* restituisce true se aggiungendo un processo del colore passato viene rispettato il 75%&lt;br /&gt;
	dei processi di un colore */&lt;br /&gt;
	bool morethan75p(colore) { &lt;br /&gt;
		return (running[colore]+1&amp;gt;=running[1-colore]*3 || (running[colore]+1)*3&amp;lt;=running[1-colore])&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	// risveglia un processo del colore passato se è possibile farlo&lt;br /&gt;
	void checkwakeup() {&lt;br /&gt;
		if (waiting.empty() == false) {&lt;br /&gt;
			colore=waiting.head() // head resituisce l'elemento in testa senza rimuoverlo&lt;br /&gt;
			if (morethan75p(colore)) { &lt;br /&gt;
				waiting.dequeue()&lt;br /&gt;
				oktoenter.signal()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter(colore) {&lt;br /&gt;
		if (morethan75p(colore)==false) {&lt;br /&gt;
			waiting.enqueue(colore)&lt;br /&gt;
			oktoenter.wait()&lt;br /&gt;
		}&lt;br /&gt;
		running[colore]++&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit(colore) {&lt;br /&gt;
		running[colore]--&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* la politica FIFO impedisce che si verifichi starvation, perché nel caso pessimo un processo&lt;br /&gt;
che vuole entrare dovrà attendere fino a che tutti quelli in esecuzione terminino */&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Daniele Cortesi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
define RED 0&lt;br /&gt;
define BLUE 1&lt;br /&gt;
int majorcolor = -1&lt;br /&gt;
int numproc[2] = 0,0&lt;br /&gt;
cond oktoenter[2]  \\bastavano due condizioni.&lt;br /&gt;
cond oktoexit[2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
	procedure entry enter(COL){&lt;br /&gt;
		if(COL == majorcolor){&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			if((proc[majorcolor]*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;lt; 75)&lt;br /&gt;
				oktoenter[COL].wait()&lt;br /&gt;
			if(majorcolor == -1)&lt;br /&gt;
				majorcolor == COL&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			majorcolor = COL&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit(COL){&lt;br /&gt;
		if(numproc[COL] + numproc[1-COL] == 1){&lt;br /&gt;
			majorcolor = -1&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == majorcolor){&lt;br /&gt;
			if(((proc[majorcolor] - 1)*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;lt; 75){&lt;br /&gt;
				oktoexit[COL].wait()&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoexit[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
define RED 0&lt;br /&gt;
define BLU 1&lt;br /&gt;
&lt;br /&gt;
limcol{&lt;br /&gt;
	/*variable*/&lt;br /&gt;
	int array[2] = 0,0;&lt;br /&gt;
	color major = -1;&lt;br /&gt;
	/*condition*/&lt;br /&gt;
	condition oktoenter[2];&lt;br /&gt;
	condition oktoleave[2];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	procedure entry enter( color ){&lt;br /&gt;
		if ( majorcolor == -1 ) &lt;br /&gt;
			majorcolor = color;&lt;br /&gt;
		if ( majorcolor == (1-color) &amp;amp;&amp;amp; newmajorcolor%(color) &amp;lt; 75% )&lt;br /&gt;
			oktoenter[color].wait();&lt;br /&gt;
		array[color]++; &lt;br /&gt;
		if ( majorcolor == -1 )            //se un processo si risveglia nel monitor vuoto deve impostare majorcolor&lt;br /&gt;
			majorcolor = color;&lt;br /&gt;
		if ( newmajorcolor%(1-color) &amp;gt;= 75% )         &lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
					}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit( color ){&lt;br /&gt;
		if ( majorcolor == color &amp;amp;&amp;amp; majorcolor_less1%(color) &amp;gt; 75% )&lt;br /&gt;
			oktoleave[color].wait();&lt;br /&gt;
		array[color]--;&lt;br /&gt;
		if ( !colorsempty() )&lt;br /&gt;
			if ( majorcolor_less1%(color) &amp;gt;= 75% )&lt;br /&gt;
				oktoleave[1-color].signal();&lt;br /&gt;
		else{&lt;br /&gt;
			majorcolor == -1;&lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
				}&lt;br /&gt;
					}&lt;br /&gt;
		 &lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
newmajorcolor%(color) calcola la nuova % del colore maggiore aggiungendo color&lt;br /&gt;
majorcolor_less1%(color) calcola la nuova % del colore maggiore togliendo color&lt;br /&gt;
*/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Pir@t@&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=514</id>
		<title>ProvaTeorica 2012.07.16</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.07.16&amp;diff=514"/>
		<updated>2014-03-28T16:51:48Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.cs.unibo.it/~renzo/so/compiti/2012-07-16.tot.pdf Link Testo]&lt;br /&gt;
&amp;lt;h2&amp;gt;Esercizio C.2&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mia Soluzione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define RED 0&lt;br /&gt;
#define BLUE 1&lt;br /&gt;
//restituisce 1 se c'e piu del 75% blue o 75% di red&lt;br /&gt;
//restituisce 0 se non c'e una maggiornza&lt;br /&gt;
int media(color){&lt;br /&gt;
	int mediared;&lt;br /&gt;
	int localinto =  into;&lt;br /&gt;
	if (color != NULL){&lt;br /&gt;
		localinto[color]++;&lt;br /&gt;
	}&lt;br /&gt;
	mediared = ((100*localinto[0])/(localinto[0]+localinto[1]));&lt;br /&gt;
	if(mediared &amp;gt;=75 || mediared &amp;lt; 25){&lt;br /&gt;
		return 1;//75% di rossi o di blue&lt;br /&gt;
	}else{&lt;br /&gt;
		return 0;// non c'e maggioranza		&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
&lt;br /&gt;
	conditon oktoenter[2];&lt;br /&gt;
	int into[2];&lt;br /&gt;
&lt;br /&gt;
	enter(color){&lt;br /&gt;
		if(media(color) != 1){// attendo perche' non c'e una maggioranza&lt;br /&gt;
			oktoenter[color].wait();&lt;br /&gt;
		}&lt;br /&gt;
		into[color]++;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	exit(color){&lt;br /&gt;
		into[color]--;&lt;br /&gt;
		if(media(1-color) == 1){&lt;br /&gt;
			oktoenter[1-color].signal();&lt;br /&gt;
		}else if(media(color) == 1){&lt;br /&gt;
			oktoenter[color].signal();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
- Midolo&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define ROSSO 0&lt;br /&gt;
#define BLU 1&lt;br /&gt;
&lt;br /&gt;
monitor limcol {&lt;br /&gt;
	condition oktoenter&lt;br /&gt;
	int running[2] // numero di processi rossi [0] e blu [1] in esecuzione&lt;br /&gt;
	queue waiting // coda dei colori dei processi in attesa&lt;br /&gt;
	&lt;br /&gt;
	/* restituisce true se aggiungendo un processo del colore passato viene rispettato il 75%&lt;br /&gt;
	dei processi di un colore */&lt;br /&gt;
	bool morethan75p(colore) { &lt;br /&gt;
		return (running[colore]+1&amp;gt;=running[1-colore]*3 || (running[colore]+1)*3&amp;lt;=running[1-colore])&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	// risveglia un processo del colore passato se è possibile farlo&lt;br /&gt;
	void checkwakeup() {&lt;br /&gt;
		if (waiting.empty() == false) {&lt;br /&gt;
			colore=waiting.head() // head resituisce l'elemento in testa senza rimuoverlo&lt;br /&gt;
			if (morethan75p(colore)) { &lt;br /&gt;
				waiting.dequeue()&lt;br /&gt;
				oktoenter.signal()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry enter(colore) {&lt;br /&gt;
		if (morethan75p(colore)==false) {&lt;br /&gt;
			waiting.enqueue(colore)&lt;br /&gt;
			oktoenter.wait()&lt;br /&gt;
		}&lt;br /&gt;
		running[colore]++&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry exit(colore) {&lt;br /&gt;
		running[colore]--&lt;br /&gt;
		checkwakeup()&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* la politica FIFO impedisce che si verifichi starvation, perché nel caso pessimo un processo&lt;br /&gt;
che vuole entrare dovrà attendere fino a che tutti quelli in esecuzione terminino */&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Daniele Cortesi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
define RED 0&lt;br /&gt;
define BLUE 1&lt;br /&gt;
int majorcolor = -1&lt;br /&gt;
int numproc[2] = 0,0&lt;br /&gt;
cond oktoenter[2]&lt;br /&gt;
cond oktoexit[2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
monitor limcol{&lt;br /&gt;
	procedure entry enter(COL){&lt;br /&gt;
		if(COL == majorcolor){&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			if((proc[majorcolor]*100/(numproc[COL] + numproc[1-COL] + 1)) &amp;lt; 75)&lt;br /&gt;
				oktoenter[COL].wait()&lt;br /&gt;
			if(majorcolor == -1)&lt;br /&gt;
				majorcolor == COL&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			numproc[COL]++&lt;br /&gt;
			majorcolor = COL&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry exit(COL){&lt;br /&gt;
		if(numproc[COL] + numproc[1-COL] == 1){&lt;br /&gt;
			majorcolor = -1&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			oktoenter[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == majorcolor){&lt;br /&gt;
			if(((proc[majorcolor] - 1)*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;lt; 75){&lt;br /&gt;
				oktoexit[COL].wait()&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else if(COL == 1-majorcolor){&lt;br /&gt;
			numproc[COL]--&lt;br /&gt;
			if(((proc[majorcolor])*100/(numproc[COL] + numproc[1-COL] - 1)) &amp;gt;= 75)&lt;br /&gt;
				oktoexit[1-COL].signal()&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.05.24&amp;diff=502</id>
		<title>ProvaTeorica 2012.05.24</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.05.24&amp;diff=502"/>
		<updated>2014-03-25T21:42:32Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2012-05-24.tot.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor santuario&lt;br /&gt;
{&lt;br /&gt;
	Go = 0;               // andare al santuario&lt;br /&gt;
	Back = 1;             // tornare indietro&lt;br /&gt;
	condition ok[2];      // 2 condizioni&lt;br /&gt;
	crossing[2] = {0, 0}; // numero di persone sul ponte&lt;br /&gt;
	visiting = 0;         // numero di persone nel santuario&lt;br /&gt;
	waiting[2] = {0, 0};  // numero di persone in attesa&lt;br /&gt;
&lt;br /&gt;
	procedure entry entraponte(dir)&lt;br /&gt;
	{&lt;br /&gt;
		/* Mi blocco se: &lt;br /&gt;
		      - il numero di persone sul ponte ha raggiunto il massimo; oppure&lt;br /&gt;
		      - la direzione e' il santuario e il numero di visitatori &lt;br /&gt;
                        (compresi quelli che stanno raggiungendo il santuario) ha raggiunto il massimo; oppure&lt;br /&gt;
		      - qualcuno sta attraversando il ponte in direzione opposta; oppure&lt;br /&gt;
		      - qualcuno sta attendendo di attraversare nel senso opposto */	&lt;br /&gt;
		if (crossing[dir] == MAXPONTE || &lt;br /&gt;
		    (dir == Go &amp;amp;&amp;amp; visiting + crossing[dir] == MAXSANTUARIO) || &lt;br /&gt;
		    crossing[1 - dir] &amp;gt; 0 || &lt;br /&gt;
		    waiting[1 - dir] &amp;gt; 0)&lt;br /&gt;
		{&lt;br /&gt;
			waiting[dir]++;&lt;br /&gt;
			ok[dir].wait();&lt;br /&gt;
			waiting[dir]--;&lt;br /&gt;
		}&lt;br /&gt;
		crossing[dir]++;&lt;br /&gt;
&lt;br /&gt;
		if (dir == Back)&lt;br /&gt;
			visiting--;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry esciponte(dir)&lt;br /&gt;
	{&lt;br /&gt;
		crossing[dir]--;&lt;br /&gt;
&lt;br /&gt;
		if (dir == Go)&lt;br /&gt;
			visiting++;&lt;br /&gt;
		&lt;br /&gt;
		// [Case 1] Nessuno sta attraversando il ponte&lt;br /&gt;
		if (crossing[dir] == 0)&lt;br /&gt;
			ok[1 - dir].signal();&lt;br /&gt;
		// [Case 2] Qualcuno sta attraversando il ponte&lt;br /&gt;
		else&lt;br /&gt;
			ok[dir].signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-TomOgn&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor santuario{&lt;br /&gt;
	#define ANDATA 0&lt;br /&gt;
	#define RITORNO 1&lt;br /&gt;
	&lt;br /&gt;
	int waiting[2];&lt;br /&gt;
	int crossing[2];&lt;br /&gt;
	condition oktoenter[2];&lt;br /&gt;
	int count; /* persone dentro al santuario */&lt;br /&gt;
	&lt;br /&gt;
	procedure entry entraponte(int dir){&lt;br /&gt;
		if (dir == ANDATA){&lt;br /&gt;
			if (crossing[1-dir] &amp;gt; 0 || crossing[dir] &amp;gt;= MAXPONTE || cout+crossing[dir] &amp;gt;= MAXSANTUARIO){&lt;br /&gt;
				waiting[dir]++;&lt;br /&gt;
				oktoenter[dir].wait();&lt;br /&gt;
				waiting[dir]--;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			if (crossing[1-dir] &amp;gt; 0 || crossing[dir] &amp;gt;= MAXPONTE){&lt;br /&gt;
				waiting[dir]++;&lt;br /&gt;
				oktoenter[dir].wait();&lt;br /&gt;
				waiting[dir]--;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		crossing[dir]++;&lt;br /&gt;
		if ((crossing[dir]+count &amp;lt; MAXSANTUARIO) &amp;amp;&amp;amp; crossing[dir] &amp;lt; MAXPONTE)&lt;br /&gt;
			oktoenter[dir].signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry esciponte(int dir){&lt;br /&gt;
		crossing[dir]--;&lt;br /&gt;
		if (dir == ANDATA){&lt;br /&gt;
			count++;&lt;br /&gt;
			if (count+crossing[dir] &amp;lt; MAXSANTUARIO) /* voi che siete in attesa andate sul ponte */&lt;br /&gt;
				oktoenter[dir].signal();&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
			count--;&lt;br /&gt;
		&lt;br /&gt;
		if (crossing[dir] == 0)&lt;br /&gt;
			oktoenter[1-dir].signal();	&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Gabriele &amp;amp; Giulia (se non va colpa di Gabriele)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
monitor santuario{&lt;br /&gt;
	int CurrentDir /* 0 = arriving , 1 = leaving */&lt;br /&gt;
	int crossing&lt;br /&gt;
	condition oktoenter&lt;br /&gt;
	condition oktoleave&lt;br /&gt;
	//queue enter&lt;br /&gt;
	//queue ponte&lt;br /&gt;
	//queue leave&lt;br /&gt;
	int fidelis /* fedeli nel tempio */&lt;br /&gt;
&lt;br /&gt;
	procedure entry entraponte(CrossingDir){&lt;br /&gt;
		if(CrossingDir != CurrentDir){&lt;br /&gt;
			if(CrossingDir == 0){&lt;br /&gt;
				//enter.enqueue()&lt;br /&gt;
				oktoenter.wait()&lt;br /&gt;
				//enter.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
			if(CrossingDir == 1){&lt;br /&gt;
				//leave.enqueue()&lt;br /&gt;
				oktoleave.wait()&lt;br /&gt;
				//leave.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		if(CrossingDir == 0){&lt;br /&gt;
			if(fidelis == MAXSANTUARIO || crossing == MAXPONTE){&lt;br /&gt;
				//ponte.enqueue()&lt;br /&gt;
				oktoenter.wait()&lt;br /&gt;
				//ponte.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
			fidelis++&lt;br /&gt;
			crossing++&lt;br /&gt;
		}&lt;br /&gt;
		if(CrossingDir == 1){&lt;br /&gt;
			if(crossing == MAXPONTE){&lt;br /&gt;
				//ponte.enqueue()&lt;br /&gt;
				oktoleave.wait()&lt;br /&gt;
				//ponte.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
			fidelis--&lt;br /&gt;
			crossing++&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	precedure entry esciponte(CrossingDir){&lt;br /&gt;
		crossing--&lt;br /&gt;
		if(crossing == 0){&lt;br /&gt;
			if(CrossingDir == 0){&lt;br /&gt;
				if(fidelis &amp;lt; MAXSANTUARIO /*&amp;amp;&amp;amp; !enter.isempty()*/){&lt;br /&gt;
					oktoenter.signal()&lt;br /&gt;
				}&lt;br /&gt;
				else{&lt;br /&gt;
					CurrentDir = 1 - CurrentDir&lt;br /&gt;
					oktoleave.signal()&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				CurrentDir = 1 - CurrentDir&lt;br /&gt;
				oktoenter.signal()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	santuario{&lt;br /&gt;
		crossing = 0&lt;br /&gt;
		CurrentDir = 0&lt;br /&gt;
		fidelis = 0&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Fede &amp;amp; Mirko&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.05.24&amp;diff=501</id>
		<title>ProvaTeorica 2012.05.24</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2012.05.24&amp;diff=501"/>
		<updated>2014-03-25T17:25:46Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;http://www.cs.unibo.it/~renzo/so/compiti/2012-05-24.tot.pdf&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor santuario&lt;br /&gt;
{&lt;br /&gt;
	Go = 0;               // andare al santuario&lt;br /&gt;
	Back = 1;             // tornare indietro&lt;br /&gt;
	condition ok[2];      // 2 condizioni&lt;br /&gt;
	crossing[2] = {0, 0}; // numero di persone sul ponte&lt;br /&gt;
	visiting = 0;         // numero di persone nel santuario&lt;br /&gt;
	waiting[2] = {0, 0};  // numero di persone in attesa&lt;br /&gt;
&lt;br /&gt;
	procedure entry entraponte(dir)&lt;br /&gt;
	{&lt;br /&gt;
		/* Mi blocco se: &lt;br /&gt;
		      - il numero di persone sul ponte ha raggiunto il massimo; oppure&lt;br /&gt;
		      - la direzione e' il santuario e il numero di visitatori &lt;br /&gt;
                        (compresi quelli che stanno raggiungendo il santuario) ha raggiunto il massimo; oppure&lt;br /&gt;
		      - qualcuno sta attraversando il ponte in direzione opposta; oppure&lt;br /&gt;
		      - qualcuno sta attendendo di attraversare nel senso opposto */	&lt;br /&gt;
		if (crossing[dir] == MAXPONTE || &lt;br /&gt;
		    (dir == Go &amp;amp;&amp;amp; visiting + crossing[dir] == MAXSANTUARIO) || &lt;br /&gt;
		    crossing[1 - dir] &amp;gt; 0 || &lt;br /&gt;
		    waiting[1 - dir] &amp;gt; 0)&lt;br /&gt;
		{&lt;br /&gt;
			waiting[dir]++;&lt;br /&gt;
			ok[dir].wait();&lt;br /&gt;
			waiting[dir]--;&lt;br /&gt;
		}&lt;br /&gt;
		crossing[dir]++;&lt;br /&gt;
&lt;br /&gt;
		if (dir == Back)&lt;br /&gt;
			visiting--;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry esciponte(dir)&lt;br /&gt;
	{&lt;br /&gt;
		crossing[dir]--;&lt;br /&gt;
&lt;br /&gt;
		if (dir == Go)&lt;br /&gt;
			visiting++;&lt;br /&gt;
		&lt;br /&gt;
		// [Case 1] Nessuno sta attraversando il ponte&lt;br /&gt;
		if (crossing[dir] == 0)&lt;br /&gt;
			ok[1 - dir].signal();&lt;br /&gt;
		// [Case 2] Qualcuno sta attraversando il ponte&lt;br /&gt;
		else&lt;br /&gt;
			ok[dir].signal();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-TomOgn&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor santuario{&lt;br /&gt;
	#define ANDATA 0&lt;br /&gt;
	#define RITORNO 1&lt;br /&gt;
	&lt;br /&gt;
	int waiting[2];&lt;br /&gt;
	int crossing[2];&lt;br /&gt;
	condition oktoenter[2];&lt;br /&gt;
	int count; /* persone dentro al santuario */&lt;br /&gt;
	&lt;br /&gt;
	procedure entry entraponte(int dir){&lt;br /&gt;
		if (dir == ANDATA){&lt;br /&gt;
			if (crossing[1-dir] &amp;gt; 0 || crossing[dir] &amp;gt;= MAXPONTE || cout+crossing[dir] &amp;gt;= MAXSANTUARIO){&lt;br /&gt;
				waiting[dir]++;&lt;br /&gt;
				oktoenter[dir].wait();&lt;br /&gt;
				waiting[dir]--;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			if (crossing[1-dir] &amp;gt; 0 || crossing[dir] &amp;gt;= MAXPONTE){&lt;br /&gt;
				waiting[dir]++;&lt;br /&gt;
				oktoenter[dir].wait();&lt;br /&gt;
				waiting[dir]--;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		crossing[dir]++;&lt;br /&gt;
		if ((crossing[dir]+count &amp;lt; MAXSANTUARIO) &amp;amp;&amp;amp; crossing[dir] &amp;lt; MAXPONTE)&lt;br /&gt;
			oktoenter[dir].signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry esciponte(int dir){&lt;br /&gt;
		crossing[dir]--;&lt;br /&gt;
		if (dir == ANDATA){&lt;br /&gt;
			count++;&lt;br /&gt;
			if (count+crossing[dir] &amp;lt; MAXSANTUARIO) /* voi che siete in attesa andate sul ponte */&lt;br /&gt;
				oktoenter[dir].signal();&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
			count--;&lt;br /&gt;
		&lt;br /&gt;
		if (crossing[dir] == 0)&lt;br /&gt;
			oktoenter[1-dir].signal();	&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Gabriele &amp;amp; Giulia (se non va colpa di Gabriele)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
monitor santuario{&lt;br /&gt;
	int CurrentDir /* 0 = arriving , 1 = leaving */&lt;br /&gt;
	int crossing&lt;br /&gt;
	condition oktoenter&lt;br /&gt;
	condition oktoleave&lt;br /&gt;
	queue enter&lt;br /&gt;
	queue ponte&lt;br /&gt;
	queue leave&lt;br /&gt;
	int fidelis /* fedeli nel tempio */&lt;br /&gt;
&lt;br /&gt;
	procedure entry entraponte(CrossingDir){&lt;br /&gt;
		if(CrossingDir != CurrentDir){&lt;br /&gt;
			if(CrossingDir == 0){&lt;br /&gt;
				enter.enqueue()&lt;br /&gt;
				oktoenter.wait()&lt;br /&gt;
				enter.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
			if(CrossingDir == 1){&lt;br /&gt;
				leave.enqueue()&lt;br /&gt;
				oktoleave.wait()&lt;br /&gt;
				leave.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		if(CrossingDir == 0){&lt;br /&gt;
			if(fidelis == MAXSANTUARIO || crossing == MAXPONTE){&lt;br /&gt;
				ponte.enqueue()&lt;br /&gt;
				oktoenter.wait()&lt;br /&gt;
				ponte.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
			fidelis++&lt;br /&gt;
			crossing++&lt;br /&gt;
		}&lt;br /&gt;
		if(CrossingDir == 1){&lt;br /&gt;
			if(crossing == MAXPONTE){&lt;br /&gt;
				ponte.enqueue()&lt;br /&gt;
				oktoleave.wait()&lt;br /&gt;
				ponte.dequeue()&lt;br /&gt;
			}&lt;br /&gt;
			fidelis--&lt;br /&gt;
			crossing++&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	precedure entry esciponte(CrossingDir){&lt;br /&gt;
		crossing--&lt;br /&gt;
		if(crossing == 0){&lt;br /&gt;
			if(CrossingDir == 0){&lt;br /&gt;
				if(fidelis &amp;lt; MAXSANTUARIO &amp;amp;&amp;amp; !enter.isempty()){&lt;br /&gt;
					oktoenter.signal()&lt;br /&gt;
				}&lt;br /&gt;
				else{&lt;br /&gt;
					CurrentDir = 1 - CurrentDir&lt;br /&gt;
					oktoleave.signal()&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				CurrentDir = 1 - CurrentDir&lt;br /&gt;
				oktoenter.signal()&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	santuario{&lt;br /&gt;
		crossing = 0&lt;br /&gt;
		CurrentDir = 0&lt;br /&gt;
		fidelis = 0&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Fede &amp;amp; Mirko&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Producer%26Consumer_MP.&amp;diff=485</id>
		<title>Producer&amp;Consumer MP.</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Producer%26Consumer_MP.&amp;diff=485"/>
		<updated>2014-03-21T19:42:40Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
MP-sincrono dato quello asincrono&lt;br /&gt;
&lt;br /&gt;
Producer(){&lt;br /&gt;
	produce(x);&lt;br /&gt;
	asend(x,Consumer);&lt;br /&gt;
	while(1){&lt;br /&gt;
		areceive(Consumer);&lt;br /&gt;
		produce(x);&lt;br /&gt;
		asend(x,Consumer);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Consumer(){&lt;br /&gt;
	while(1){&lt;br /&gt;
		x = areceive(Producer);&lt;br /&gt;
                asend(ACK,Producer);&lt;br /&gt;
		consume(x);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
MP-asincrono dato quello sincrono&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;slideconcorrenzapg201.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Producer(){&lt;br /&gt;
	while(1){&lt;br /&gt;
		produce(x);&lt;br /&gt;
		asend(x,Consumer);	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
Consumer(){&lt;br /&gt;
	while(1){&lt;br /&gt;
		x=areceive(Producer);&lt;br /&gt;
		consume(x);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Fede&amp;amp;Pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=378</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=378"/>
		<updated>2013-11-30T14:40:12Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
ESERCIZIO 3.&lt;br /&gt;
*/&lt;br /&gt;
#include&amp;lt;unistd.h&amp;gt;  &lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt; &lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt; &lt;br /&gt;
#include&amp;lt;string.h&amp;gt; &lt;br /&gt;
#include&amp;lt;dirent.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
&lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )//si deve escludere &amp;quot;..&amp;quot;&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )//si deve escludere &amp;quot;.&amp;quot;&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);//torna 0 al successo -1 altrimenti&lt;br /&gt;
						if(datest==-1) //se simlink fallisce =&amp;gt; link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)//finchè simlink non ha successo&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								free(istr);&lt;br /&gt;
								free(pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					} &lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
			free(pathwithname);&lt;br /&gt;
			free(pathwithname2);&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
	free(namelist);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=377</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=377"/>
		<updated>2013-11-30T09:02:06Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
ESERCIZIO 3.&lt;br /&gt;
*/&lt;br /&gt;
#include&amp;lt;unistd.h&amp;gt;  &lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt; &lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt; &lt;br /&gt;
#include&amp;lt;string.h&amp;gt; &lt;br /&gt;
#include&amp;lt;dirent.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
&lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )//si deve escludere &amp;quot;..&amp;quot;&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )//si deve escludere &amp;quot;.&amp;quot;&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);//torna 0 al successo -1 altrimenti&lt;br /&gt;
						if(datest==-1) //se simlink fallisce =&amp;gt; link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)//finchè simlink non ha successo&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								free(istr);&lt;br /&gt;
								free(pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					} &lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
			free(pathwithname);&lt;br /&gt;
			free(pathwithname2);&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=376</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=376"/>
		<updated>2013-11-30T08:42:31Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
ESERCIZIO 3.&lt;br /&gt;
*/&lt;br /&gt;
#include&amp;lt;unistd.h&amp;gt;  &lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt; &lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt; &lt;br /&gt;
#include&amp;lt;string.h&amp;gt; &lt;br /&gt;
#include&amp;lt;dirent.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
&lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);&lt;br /&gt;
						if(datest==-1) //link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								free(istr);&lt;br /&gt;
								free(pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					} &lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
			free(pathwithname);&lt;br /&gt;
			free(pathwithname2);&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=375</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=375"/>
		<updated>2013-11-29T22:16:19Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
ESERCIZIO 3.&lt;br /&gt;
*/&lt;br /&gt;
#include&amp;lt;unistd.h&amp;gt;  &lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt; &lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt; &lt;br /&gt;
#include&amp;lt;string.h&amp;gt; &lt;br /&gt;
#include&amp;lt;dirent.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);&lt;br /&gt;
						if(datest==-1) //link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					} &lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=374</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=374"/>
		<updated>2013-11-29T22:02:16Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
ESERCIZIO 3.&lt;br /&gt;
*/&lt;br /&gt;
#include&amp;lt;unistd.h&amp;gt;  &lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt; &lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt; &lt;br /&gt;
#include&amp;lt;string.h&amp;gt; &lt;br /&gt;
#include&amp;lt;dirent.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
&lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);&lt;br /&gt;
						if(datest==-1) //link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					} &lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=373</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=373"/>
		<updated>2013-11-29T21:51:45Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include&amp;lt;unistd.h&amp;gt;  &lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt; &lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt; &lt;br /&gt;
#include&amp;lt;string.h&amp;gt; &lt;br /&gt;
#include&amp;lt;dirent.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
&lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);&lt;br /&gt;
						if(datest==-1) //link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
					} &lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=372</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=372"/>
		<updated>2013-11-29T21:49:15Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include&amp;lt;unistd.h&amp;gt;  &lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt; &lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt; &lt;br /&gt;
#include&amp;lt;string.h&amp;gt; &lt;br /&gt;
#include&amp;lt;dirent.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt; &lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
&lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);&lt;br /&gt;
						if(datest==-1) //link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
						&lt;br /&gt;
					} &lt;br /&gt;
&lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=371</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=371"/>
		<updated>2013-11-29T21:48:34Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Versione by Daniele Cortesi:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from sys import argv&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
#controllo se il programma e' stato chiamato correttamente&lt;br /&gt;
if len(argv)&amp;lt;3:&lt;br /&gt;
	print &amp;quot;uso: programma cartella1 cartella2&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
	&lt;br /&gt;
dir1=argv[1]&lt;br /&gt;
dir2=argv[2]&lt;br /&gt;
&lt;br /&gt;
#controllo che gli argomenti siano effettivamente cartelle&lt;br /&gt;
if not os.path.isdir(dir1) or  not os.path.isdir(dir2):&lt;br /&gt;
	print &amp;quot;cartelle non valide&amp;quot;&lt;br /&gt;
	exit(1)&lt;br /&gt;
&lt;br /&gt;
cartelle=[os.getcwd()+&amp;quot;/&amp;quot;+dir1] #lista che conterra' mano a mano tutte le sottocartelle&lt;br /&gt;
files={} #dizionario con nomefile: [lista con tutti i file che si chiamano &amp;quot;nomefile&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
while len(cartelle)&amp;gt;0:&lt;br /&gt;
	c=cartelle.pop() &lt;br /&gt;
	for f in os.listdir(c): #analizzo tutti i file nella cartella c&lt;br /&gt;
		#se f non e' una cartella, allora lo inserisco nel dizionario se non c'e', altrimenti aggiungo il suo percorso alla lista&lt;br /&gt;
		if not os.path.isdir(c+&amp;quot;/&amp;quot;+f):&lt;br /&gt;
			if not files.has_key(f):&lt;br /&gt;
				files[f]=[c+&amp;quot;/&amp;quot;+f]&lt;br /&gt;
			else: files[f].append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		#se f invece e' una cartella, la aggiungo alla lista cosi' alla prossima iterazione (o dopo in caso di piu' cartelle) verra' analizzata&lt;br /&gt;
		else: cartelle.append(c+&amp;quot;/&amp;quot;+f)&lt;br /&gt;
		&lt;br /&gt;
#creo i link simbolici	&lt;br /&gt;
for k in files.keys():&lt;br /&gt;
	for i,f in enumerate(files[k]):&lt;br /&gt;
		link=k&lt;br /&gt;
		if (i&amp;gt;0): link+=str(i)&lt;br /&gt;
		os.symlink(f, dir2+&amp;quot;/&amp;quot;+link)&lt;br /&gt;
&lt;br /&gt;
exit(0)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Osservazioni==&lt;br /&gt;
Per prima cosa, bel lavoro!&amp;lt;br/&amp;gt;&lt;br /&gt;
Di seguito riporto alcune osservazioni che mi sono venute in mente, prendetele assolutamente con soli fini &amp;quot;costruttivi&amp;quot;! &lt;br /&gt;
* Se non sbaglio, i due programmi (quello di Tommaso e quello di Fede) hanno un comportamento diverso per quanto concerne l'interpretazione del nome file e, in particolare, dell'estensione:&lt;br /&gt;
** Per Tommaso:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example1&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example2&lt;br /&gt;
** Per Fede:&lt;br /&gt;
*** dir1/example.pdf --&amp;gt; example.pdf&lt;br /&gt;
*** dir1/example.txt --&amp;gt; example.txt&lt;br /&gt;
*** dir1/dirX/example.pdf --&amp;gt; example.pdf1&lt;br /&gt;
** interpretando in modo &amp;quot;stringente&amp;quot; del testo dell'esercizio avrei ipotizzato un comportamento come quello di Fede.&lt;br /&gt;
* Nel codice sorgente c'è in generale poco &amp;quot;commento&amp;quot;. Commentare il codice è essenziale: permette ad altri di capire immediatamente le scelte implementative fatte e permette a voi di capire al volo il perché di queste scelte nel caso dobbiate riprendere in mano il vostro codice dopo un po' di tempo. Quindi: commentate!!!&lt;br /&gt;
* Bash si presta molto all'esercizio&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
void collectandlink(char *arg1, char *carg2)&lt;br /&gt;
{ &lt;br /&gt;
	struct dirent **namelist; &lt;br /&gt;
	int n; &lt;br /&gt;
	n = scandir( arg1 , &amp;amp;namelist, 0, alphasort); &lt;br /&gt;
&lt;br /&gt;
	if (n &amp;lt; 0) &lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;); &lt;br /&gt;
	else &lt;br /&gt;
	{ &lt;br /&gt;
		while(n--)&lt;br /&gt;
		{ &lt;br /&gt;
			int i;&lt;br /&gt;
			char* istr;&lt;br /&gt;
			int datest;&lt;br /&gt;
			char *pathnametmp;&lt;br /&gt;
			char *pathwithname=(char *)malloc(512);&lt;br /&gt;
			char *pathwithname2=(char *)malloc(512);&lt;br /&gt;
			strcpy(pathwithname,arg1);&lt;br /&gt;
			strcpy(pathwithname2,carg2);&lt;br /&gt;
			strcat(pathwithname,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname2,&amp;quot;/&amp;quot;);&lt;br /&gt;
			strcat(pathwithname,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			strcat(pathwithname2,namelist[n]-&amp;gt;d_name);&lt;br /&gt;
			struct stat s; &lt;br /&gt;
			if( stat(pathwithname,&amp;amp;s) == 0 ) &lt;br /&gt;
			{  &lt;br /&gt;
				if( s.st_mode &amp;amp; S_IFDIR ) //è un dir&lt;br /&gt;
				{ &lt;br /&gt;
					if ( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;..&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					} &lt;br /&gt;
					if( strcmp( namelist[n]-&amp;gt;d_name , &amp;quot;.&amp;quot; ) == 0 )&lt;br /&gt;
					{ &lt;br /&gt;
						continue; &lt;br /&gt;
					}  &lt;br /&gt;
					else &lt;br /&gt;
					{&lt;br /&gt;
						collectandlink(pathwithname,carg2);&lt;br /&gt;
					}&lt;br /&gt;
				} &lt;br /&gt;
				else &lt;br /&gt;
				{&lt;br /&gt;
					if( s.st_mode &amp;amp; S_IFREG ) //è un file&lt;br /&gt;
					{ &lt;br /&gt;
						datest=symlink(pathwithname,pathwithname2);&lt;br /&gt;
						if(datest==-1) //link esiste&lt;br /&gt;
						{&lt;br /&gt;
							i=1;&lt;br /&gt;
							while(datest!=0)&lt;br /&gt;
							{&lt;br /&gt;
								istr=(char *)malloc(32);&lt;br /&gt;
								pathnametmp=(char *)malloc(544);&lt;br /&gt;
								strcpy(pathnametmp,pathwithname2);&lt;br /&gt;
								sprintf(istr, &amp;quot;%d&amp;quot;, i);&lt;br /&gt;
								strcat(pathnametmp,istr);&lt;br /&gt;
								datest=symlink(pathwithname,pathnametmp);&lt;br /&gt;
								i=i+1;&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
						&lt;br /&gt;
					} &lt;br /&gt;
&lt;br /&gt;
				} &lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		} &lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){ &lt;br /&gt;
collectandlink(argv[1],argv[2]); &lt;br /&gt;
return 1; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Da fede&amp;amp;pirata&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=363</id>
		<title>ProvaPratica 2013.05.29</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=363"/>
		<updated>2013-11-26T22:47:27Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
29 maggio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.05.29.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 2:&lt;br /&gt;
        print(&amp;quot;The function requires one argument to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    topDir = str(sys.argv[1])&lt;br /&gt;
    if not os.path.isdir(topDir):&lt;br /&gt;
        print(&amp;quot;The parameter should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file extension - total size}&lt;br /&gt;
    extensionSize = { }&lt;br /&gt;
    GetSize(topDir, extensionSize)&lt;br /&gt;
    &lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(extensionSize)&lt;br /&gt;
&lt;br /&gt;
def GetSize(topDir, extensionSize):&lt;br /&gt;
    for dirPath, dirNames, files in os.walk(topDir):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            # 'example.mp3' -&amp;gt; ['example', 'mp3']&lt;br /&gt;
            # 'example.tar.gz' -&amp;gt; ['example', 'tar', 'gz']&lt;br /&gt;
            parts = file.split('.')&lt;br /&gt;
            # ['example', 'mp3'] -&amp;gt; ['mp3']&lt;br /&gt;
            # ['example', 'tar', 'gz'] -&amp;gt; ['tar', 'gz']&lt;br /&gt;
            parts = parts[1:]&lt;br /&gt;
            # ['mp3'] -&amp;gt; '.mp3'&lt;br /&gt;
            # ['tar', 'gz'] -&amp;gt; '.tar.gz'&lt;br /&gt;
            fileExtension = &amp;quot;.{0}&amp;quot;.format(&amp;quot;.&amp;quot;.join(str(part) for part in parts))&lt;br /&gt;
            &lt;br /&gt;
            # Compute the size in Bytes and update the dictionary&lt;br /&gt;
            filePath = os.path.join(dirPath, file)   &lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            extensionSize[fileExtension] = extensionSize.get(fileExtension, 0) + fileSize&lt;br /&gt;
&lt;br /&gt;
# Print results&lt;br /&gt;
def PrintResults(extensionSize):&lt;br /&gt;
    for key, value in sorted(extensionSize.items()):&lt;br /&gt;
        print('{0}: {1} Bytes.'.format(key, value))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, sys, copy&lt;br /&gt;
&lt;br /&gt;
def dotsubstr(a):#restituisce la sottostringa .suffisso&lt;br /&gt;
	#fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	i=0&lt;br /&gt;
	try:&lt;br /&gt;
		while a[i]!='.':&lt;br /&gt;
			i=i+1&lt;br /&gt;
		return a[i:]&lt;br /&gt;
	except IndexError:&lt;br /&gt;
		return -1&lt;br /&gt;
&lt;br /&gt;
def compliarg(li,arg):#restituisce una lista di tutti gli elementi contenenti la sottostringa arg come suffisso&lt;br /&gt;
	res=[]&lt;br /&gt;
	while li != []:&lt;br /&gt;
		a=li.pop()&lt;br /&gt;
		if a.endswith(arg): res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listremintsect(l2,l1):#restituisce una lista res = l1 - intersezione di l1 ed l2&lt;br /&gt;
	res=[]&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		a=l1.pop()&lt;br /&gt;
		if not a in l2: res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def createpathlist(c,path):#restituisce una lista di path 'path' relativi ai file contenuti in c.&lt;br /&gt;
	res = []&lt;br /&gt;
	while c != []:&lt;br /&gt;
		res.append('{0}/{1}'.format(path,c.pop()))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def totsizes(d): #data una lista d di path restituisce la somma di tutti i size di d&lt;br /&gt;
	res = 0&lt;br /&gt;
	while d != []:&lt;br /&gt;
		a = d.pop()&lt;br /&gt;
		if os.path.isfile('{0}'.format(a)):&lt;br /&gt;
			res = res + os.path.getsize('{0}'.format(a))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listsubstr(arg): #ritorna un dizionario del tipo diz[str(suffisso)] = int(size relativo al suffisso)&lt;br /&gt;
	res = {}&lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		fcdtmp=copy.deepcopy(fcd) #BUGGONE SENZA COPY!!!!!!&lt;br /&gt;
		a = fcd.pop()&lt;br /&gt;
		b = dotsubstr(a)&lt;br /&gt;
		if b == -1: continue&lt;br /&gt;
		else: pass&lt;br /&gt;
		c = compliarg(fcdtmp,b)&lt;br /&gt;
		s=copy.deepcopy(c) #!!!!!!!!!!!!!!!!!!!!!!!!!&lt;br /&gt;
		d = createpathlist(c,arg)&lt;br /&gt;
		res[b] = totsizes(d)&lt;br /&gt;
&lt;br /&gt;
		fcd = listremintsect(s,fcd)&lt;br /&gt;
&lt;br /&gt;
	return res&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	res = listsubstr(sys.argv[1])&lt;br /&gt;
	a=list(res.keys())&lt;br /&gt;
	while a != []:&lt;br /&gt;
		b = a.pop()&lt;br /&gt;
		print('{0}:\t{1}'.format(b,res[b]))&lt;br /&gt;
except OSError:&lt;br /&gt;
	print(&amp;quot;Could not solve path&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Esercizio 1: Linguaggio C&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/eventfd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BUFFSIZE 10&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){&lt;br /&gt;
	int efd,n,i;&lt;br /&gt;
	char buf1[BUFFSIZE];&lt;br /&gt;
	char buf2[BUFFSIZE];&lt;br /&gt;
	&lt;br /&gt;
	do{&lt;br /&gt;
		efd = eventfd(0,0);&lt;br /&gt;
	}while(efd&amp;lt;0);&lt;br /&gt;
	&lt;br /&gt;
	while(1){&lt;br /&gt;
		if(fork()){ /*padre*/&lt;br /&gt;
				read(0,buf1,sizeof(buf1)); /*0 indica lo standard input*/&lt;br /&gt;
				write(efd, buf1, sizeof(buf1));&lt;br /&gt;
				}&lt;br /&gt;
			&lt;br /&gt;
		else{ /*figlio*/&lt;br /&gt;
			read(efd, buf2, sizeof(buf2));&lt;br /&gt;
			n=atoi(buf2);&lt;br /&gt;
			for(i=0; i&amp;lt;n; i++) printf(&amp;quot;x\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
GiuliaN. con grande aiuto da parte dei colleghi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 in bash(Pirata &amp;amp; Fede):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*.* ; do&lt;br /&gt;
	somma=0&lt;br /&gt;
	ext=${f##*.}&lt;br /&gt;
	for file in *.&amp;quot;$ext&amp;quot;&lt;br /&gt;
	do&lt;br /&gt;
		somma=$(expr $somma + $(stat -c%s &amp;quot;$file&amp;quot;))&lt;br /&gt;
	done&lt;br /&gt;
	echo -n &amp;quot;size of file with extension &amp;quot;$ext&amp;quot; : &amp;quot;&lt;br /&gt;
	echo &amp;quot;$somma&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=362</id>
		<title>ProvaPratica 2013.05.29</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=362"/>
		<updated>2013-11-26T22:45:59Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
29 maggio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.05.29.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 2:&lt;br /&gt;
        print(&amp;quot;The function requires one argument to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    topDir = str(sys.argv[1])&lt;br /&gt;
    if not os.path.isdir(topDir):&lt;br /&gt;
        print(&amp;quot;The parameter should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file extension - total size}&lt;br /&gt;
    extensionSize = { }&lt;br /&gt;
    GetSize(topDir, extensionSize)&lt;br /&gt;
    &lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(extensionSize)&lt;br /&gt;
&lt;br /&gt;
def GetSize(topDir, extensionSize):&lt;br /&gt;
    for dirPath, dirNames, files in os.walk(topDir):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            # 'example.mp3' -&amp;gt; ['example', 'mp3']&lt;br /&gt;
            # 'example.tar.gz' -&amp;gt; ['example', 'tar', 'gz']&lt;br /&gt;
            parts = file.split('.')&lt;br /&gt;
            # ['example', 'mp3'] -&amp;gt; ['mp3']&lt;br /&gt;
            # ['example', 'tar', 'gz'] -&amp;gt; ['tar', 'gz']&lt;br /&gt;
            parts = parts[1:]&lt;br /&gt;
            # ['mp3'] -&amp;gt; '.mp3'&lt;br /&gt;
            # ['tar', 'gz'] -&amp;gt; '.tar.gz'&lt;br /&gt;
            fileExtension = &amp;quot;.{0}&amp;quot;.format(&amp;quot;.&amp;quot;.join(str(part) for part in parts))&lt;br /&gt;
            &lt;br /&gt;
            # Compute the size in Bytes and update the dictionary&lt;br /&gt;
            filePath = os.path.join(dirPath, file)   &lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            extensionSize[fileExtension] = extensionSize.get(fileExtension, 0) + fileSize&lt;br /&gt;
&lt;br /&gt;
# Print results&lt;br /&gt;
def PrintResults(extensionSize):&lt;br /&gt;
    for key, value in sorted(extensionSize.items()):&lt;br /&gt;
        print('{0}: {1} Bytes.'.format(key, value))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, sys, copy&lt;br /&gt;
&lt;br /&gt;
def dotsubstr(a):#restituisce la sottostringa .suffisso&lt;br /&gt;
	#fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	i=0&lt;br /&gt;
	try:&lt;br /&gt;
		while a[i]!='.':&lt;br /&gt;
			i=i+1&lt;br /&gt;
		return a[i:]&lt;br /&gt;
	except IndexError:&lt;br /&gt;
		return -1&lt;br /&gt;
&lt;br /&gt;
def compliarg(li,arg):#restituisce una lista di tutti gli elementi contenenti la sottostringa arg come suffisso&lt;br /&gt;
	res=[]&lt;br /&gt;
	while li != []:&lt;br /&gt;
		a=li.pop()&lt;br /&gt;
		if a.endswith(arg): res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listremintsect(l2,l1):#restituisce una lista res = l1 - intersezione di l1 ed l2&lt;br /&gt;
	res=[]&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		a=l1.pop()&lt;br /&gt;
		if not a in l2: res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def createpathlist(c,path):#restituisce una lista di path 'path' relativi ai file contenuti in c.&lt;br /&gt;
	res = []&lt;br /&gt;
	while c != []:&lt;br /&gt;
		res.append('{0}/{1}'.format(path,c.pop()))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def totsizes(d): #data una lista d di path restituisce la somma di tutti i size di d&lt;br /&gt;
	res = 0&lt;br /&gt;
	while d != []:&lt;br /&gt;
		a = d.pop()&lt;br /&gt;
		if os.path.isfile('{0}'.format(a)):&lt;br /&gt;
			res = res + os.path.getsize('{0}'.format(a))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listsubstr(arg): #ritorna un dizionario del tipo diz[str(suffisso)] = int(size relativo al suffisso)&lt;br /&gt;
	res = {}&lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		fcdtmp=copy.deepcopy(fcd) #BUGGONE SENZA COPY!!!!!!&lt;br /&gt;
		a = fcd.pop()&lt;br /&gt;
		b = dotsubstr(a)&lt;br /&gt;
		if b == -1: continue&lt;br /&gt;
		else: pass&lt;br /&gt;
		c = compliarg(fcdtmp,b)&lt;br /&gt;
		s=copy.deepcopy(c) #!!!!!!!!!!!!!!!!!!!!!!!!!&lt;br /&gt;
		d = createpathlist(c,arg)&lt;br /&gt;
		res[b] = totsizes(d)&lt;br /&gt;
&lt;br /&gt;
		fcd = listremintsect(s,fcd)&lt;br /&gt;
&lt;br /&gt;
	return res&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	res = listsubstr(sys.argv[1])&lt;br /&gt;
	a=list(res.keys())&lt;br /&gt;
	while a != []:&lt;br /&gt;
		b = a.pop()&lt;br /&gt;
		print('{0}:\t{1}'.format(b,res[b]))&lt;br /&gt;
except OSError:&lt;br /&gt;
	print(&amp;quot;Could not solve path&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Esercizio 1: Linguaggio C&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/eventfd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BUFFSIZE 10&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){&lt;br /&gt;
	int efd,n,i;&lt;br /&gt;
	char buf1[BUFFSIZE];&lt;br /&gt;
	char buf2[BUFFSIZE];&lt;br /&gt;
	&lt;br /&gt;
	do{&lt;br /&gt;
		efd = eventfd(0,0);&lt;br /&gt;
	}while(efd&amp;lt;0);&lt;br /&gt;
	&lt;br /&gt;
	while(1){&lt;br /&gt;
		if(fork()){ /*padre*/&lt;br /&gt;
				read(0,buf1,sizeof(buf1)); /*0 indica lo standard input*/&lt;br /&gt;
				write(efd, buf1, sizeof(buf1));&lt;br /&gt;
				}&lt;br /&gt;
			&lt;br /&gt;
		else{ /*figlio*/&lt;br /&gt;
			read(efd, buf2, sizeof(buf2));&lt;br /&gt;
			n=atoi(buf2);&lt;br /&gt;
			for(i=0; i&amp;lt;n; i++) printf(&amp;quot;x\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
GiuliaN. con grande aiuto da parte dei colleghi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 in bash(Pirata &amp;amp; Fede):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*.*; do&lt;br /&gt;
	somma=0&lt;br /&gt;
	ext=${f##*.}&lt;br /&gt;
	for file in *.$ext; do&lt;br /&gt;
		somma=$(expr $somma + $(stat -c%s &amp;quot;$file&amp;quot;))&lt;br /&gt;
	done&lt;br /&gt;
	echo -n &amp;quot;size of file with extension $ext : &amp;quot;&lt;br /&gt;
	echo &amp;quot;$somma&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=358</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=358"/>
		<updated>2013-11-25T23:57:13Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for filePaths in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        # No files with same size =&amp;gt; No files with same content&lt;br /&gt;
        if len(filePaths) &amp;lt; 2: break&lt;br /&gt;
        PopulateSameContent(filePaths, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(filePaths, sameContent):&lt;br /&gt;
    for filePath in filePaths:&lt;br /&gt;
        md5 = GetMd5Hash(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Get the MD5 hash without loading the whole file to memory&lt;br /&gt;
# Break the file in chunks whose size is a multiple of 128&lt;br /&gt;
# This takes advantage of the fact that MD5 has 128-byte digest blocks&lt;br /&gt;
def GetMd5Hash(filePath, blockSize = 2 ** 20):&lt;br /&gt;
    digest = hashlib.md5()&lt;br /&gt;
    with open(filePath, &amp;quot;rb&amp;quot;) as file:&lt;br /&gt;
        for chunk in iter(lambda: file.read(blockSize), b''): &lt;br /&gt;
            digest.update(chunk)&lt;br /&gt;
    return digest.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print(&amp;quot;Lists of files having same content:&amp;quot;)&lt;br /&gt;
    for files in sorted(sameContent.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2: break&lt;br /&gt;
        print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(file for file in files)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	l1&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
==Bash==&lt;br /&gt;
Qualche idea per Bash...&amp;lt;br/&amp;gt;&lt;br /&gt;
Si potrebbero usare:&amp;lt;br/&amp;gt;&lt;br /&gt;
Per la dimensione in byte dei &amp;lt;file&amp;gt;:&lt;br /&gt;
 fileSize=$(stat --format=%s &amp;lt;file&amp;gt;)&lt;br /&gt;
Per avere l'output del solo hash md5 (senza l'ausilio di altri comandi):&lt;br /&gt;
 fileHashMd5=$(md5sum &amp;lt;file&amp;gt; | while read fileHash fileName; do echo $fileHash; done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Fede&amp;amp;Alessio#&lt;br /&gt;
for file in *; do&lt;br /&gt;
	if [[ -f &amp;quot;$file&amp;quot; ]] ; then&lt;br /&gt;
		filesize=$(stat -c%s &amp;quot;$file&amp;quot;)&lt;br /&gt;
		for file2 in *; do&lt;br /&gt;
			if [[ -f &amp;quot;$file2&amp;quot; ]] ; then&lt;br /&gt;
				if [[ &amp;quot;$file&amp;quot; = &amp;quot;$file2&amp;quot; ]]; then &lt;br /&gt;
					continue&lt;br /&gt;
				fi&lt;br /&gt;
				filesize2=$(stat -c%s &amp;quot;$file2&amp;quot;)&lt;br /&gt;
				if [[ $filesize -eq $filesize2 ]]; then&lt;br /&gt;
					diff &amp;quot;$file&amp;quot; &amp;quot;$file2&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;&amp;quot;$file&amp;quot; == &amp;quot;$file2&amp;quot;&amp;quot;  ###&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
#Purtroppo non siamo riusciti a finire e abbiamo optato per una soluzione poco efficiente con un diff, poi continueremo per rendarlà un po migliore&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=357</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=357"/>
		<updated>2013-11-25T23:27:46Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for filePaths in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        # No files with same size =&amp;gt; No files with same content&lt;br /&gt;
        if len(filePaths) &amp;lt; 2: break&lt;br /&gt;
        PopulateSameContent(filePaths, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(filePaths, sameContent):&lt;br /&gt;
    for filePath in filePaths:&lt;br /&gt;
        md5 = GetMd5Hash(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Get the MD5 hash without loading the whole file to memory&lt;br /&gt;
# Break the file in chunks whose size is a multiple of 128&lt;br /&gt;
# This takes advantage of the fact that MD5 has 128-byte digest blocks&lt;br /&gt;
def GetMd5Hash(filePath, blockSize = 2 ** 20):&lt;br /&gt;
    digest = hashlib.md5()&lt;br /&gt;
    with open(filePath, &amp;quot;rb&amp;quot;) as file:&lt;br /&gt;
        for chunk in iter(lambda: file.read(blockSize), b''): &lt;br /&gt;
            digest.update(chunk)&lt;br /&gt;
    return digest.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print(&amp;quot;Lists of files having same content:&amp;quot;)&lt;br /&gt;
    for files in sorted(sameContent.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2: break&lt;br /&gt;
        print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(file for file in files)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	l1&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
==Bash==&lt;br /&gt;
Qualche idea per Bash...&amp;lt;br/&amp;gt;&lt;br /&gt;
Si potrebbero usare:&amp;lt;br/&amp;gt;&lt;br /&gt;
Per la dimensione in byte dei &amp;lt;file&amp;gt;:&lt;br /&gt;
 fileSize=$(stat --format=%s &amp;lt;file&amp;gt;)&lt;br /&gt;
Per avere l'output del solo hash md5 (senza l'ausilio di altri comandi):&lt;br /&gt;
 fileHashMd5=$(md5sum &amp;lt;file&amp;gt; | while read fileHash fileName; do echo $fileHash; done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Fede&amp;amp;Alessio#&lt;br /&gt;
for file in *; do&lt;br /&gt;
	if [[ -f &amp;quot;$file&amp;quot; ]] ; then&lt;br /&gt;
		filesize=$(stat -c%s &amp;quot;$file&amp;quot;)&lt;br /&gt;
		for file2 in *; do&lt;br /&gt;
			if [[ -f &amp;quot;$file2&amp;quot; ]] ; then&lt;br /&gt;
				if [[ &amp;quot;$file&amp;quot; = &amp;quot;$file2&amp;quot; ]]; then &lt;br /&gt;
					continue&lt;br /&gt;
				fi&lt;br /&gt;
				filesize2=$(stat -c%s &amp;quot;$file2&amp;quot;)&lt;br /&gt;
				if [[ $filesize -eq $filesize2 ]]; then&lt;br /&gt;
					diff &amp;quot;$file&amp;quot; &amp;quot;$file2&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;$file&amp;quot; &amp;quot;$file2&amp;quot; ###&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
#Purtroppo non siamo riusciti a finire e abbiamo optato per una soluzione poco efficiente con un diff, poi continueremo per rendarlà un po migliore&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=356</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=356"/>
		<updated>2013-11-25T23:27:13Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for filePaths in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        # No files with same size =&amp;gt; No files with same content&lt;br /&gt;
        if len(filePaths) &amp;lt; 2: break&lt;br /&gt;
        PopulateSameContent(filePaths, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(filePaths, sameContent):&lt;br /&gt;
    for filePath in filePaths:&lt;br /&gt;
        md5 = GetMd5Hash(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Get the MD5 hash without loading the whole file to memory&lt;br /&gt;
# Break the file in chunks whose size is a multiple of 128&lt;br /&gt;
# This takes advantage of the fact that MD5 has 128-byte digest blocks&lt;br /&gt;
def GetMd5Hash(filePath, blockSize = 2 ** 20):&lt;br /&gt;
    digest = hashlib.md5()&lt;br /&gt;
    with open(filePath, &amp;quot;rb&amp;quot;) as file:&lt;br /&gt;
        for chunk in iter(lambda: file.read(blockSize), b''): &lt;br /&gt;
            digest.update(chunk)&lt;br /&gt;
    return digest.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print(&amp;quot;Lists of files having same content:&amp;quot;)&lt;br /&gt;
    for files in sorted(sameContent.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2: break&lt;br /&gt;
        print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(file for file in files)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	l1&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
==Bash==&lt;br /&gt;
Qualche idea per Bash...&amp;lt;br/&amp;gt;&lt;br /&gt;
Si potrebbero usare:&amp;lt;br/&amp;gt;&lt;br /&gt;
Per la dimensione in byte dei &amp;lt;file&amp;gt;:&lt;br /&gt;
 fileSize=$(stat --format=%s &amp;lt;file&amp;gt;)&lt;br /&gt;
Per avere l'output del solo hash md5 (senza l'ausilio di altri comandi):&lt;br /&gt;
 fileHashMd5=$(md5sum &amp;lt;file&amp;gt; | while read fileHash fileName; do echo $fileHash; done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Fede&amp;amp;Alessio#&lt;br /&gt;
for file in *; do&lt;br /&gt;
	if [[ -f &amp;quot;$file&amp;quot; ]] ; then&lt;br /&gt;
		filesize=$(stat -c%s &amp;quot;$file&amp;quot;)&lt;br /&gt;
		for file2 in *; do&lt;br /&gt;
			if [[ -f &amp;quot;$file2&amp;quot; ]] ; then&lt;br /&gt;
				if [[ &amp;quot;$file&amp;quot; = &amp;quot;$file2&amp;quot; ]]; then &lt;br /&gt;
					continue&lt;br /&gt;
				fi&lt;br /&gt;
				filesize2=$(stat -c%s &amp;quot;$file2&amp;quot;)&lt;br /&gt;
				if [[ $filesize -eq $filesize2 ]]; then&lt;br /&gt;
					diff &amp;quot;$file&amp;quot; &amp;quot;$file2&amp;quot; &amp;amp;&amp;amp; echo $file $file2 ###&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
#Purtroppo non siamo riusciti a finire e abbiamo optato per una soluzione poco efficiente con un diff, poi continueremo per rendarlà un po migliore&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=355</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=355"/>
		<updated>2013-11-25T23:26:57Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for filePaths in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        # No files with same size =&amp;gt; No files with same content&lt;br /&gt;
        if len(filePaths) &amp;lt; 2: break&lt;br /&gt;
        PopulateSameContent(filePaths, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(filePaths, sameContent):&lt;br /&gt;
    for filePath in filePaths:&lt;br /&gt;
        md5 = GetMd5Hash(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Get the MD5 hash without loading the whole file to memory&lt;br /&gt;
# Break the file in chunks whose size is a multiple of 128&lt;br /&gt;
# This takes advantage of the fact that MD5 has 128-byte digest blocks&lt;br /&gt;
def GetMd5Hash(filePath, blockSize = 2 ** 20):&lt;br /&gt;
    digest = hashlib.md5()&lt;br /&gt;
    with open(filePath, &amp;quot;rb&amp;quot;) as file:&lt;br /&gt;
        for chunk in iter(lambda: file.read(blockSize), b''): &lt;br /&gt;
            digest.update(chunk)&lt;br /&gt;
    return digest.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print(&amp;quot;Lists of files having same content:&amp;quot;)&lt;br /&gt;
    for files in sorted(sameContent.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2: break&lt;br /&gt;
        print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(file for file in files)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	l1&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
==Bash==&lt;br /&gt;
Qualche idea per Bash...&amp;lt;br/&amp;gt;&lt;br /&gt;
Si potrebbero usare:&amp;lt;br/&amp;gt;&lt;br /&gt;
Per la dimensione in byte dei &amp;lt;file&amp;gt;:&lt;br /&gt;
 fileSize=$(stat --format=%s &amp;lt;file&amp;gt;)&lt;br /&gt;
Per avere l'output del solo hash md5 (senza l'ausilio di altri comandi):&lt;br /&gt;
 fileHashMd5=$(md5sum &amp;lt;file&amp;gt; | while read fileHash fileName; do echo $fileHash; done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Fede&amp;amp;Alessio#&lt;br /&gt;
for file in *; do&lt;br /&gt;
	if [[ -f &amp;quot;$file&amp;quot; ]] ; then&lt;br /&gt;
		filesize=$(stat -c%s &amp;quot;$file&amp;quot;)&lt;br /&gt;
		for file2 in *; do&lt;br /&gt;
			if [[ -f &amp;quot;$file2&amp;quot; ]] ; then&lt;br /&gt;
				if [[ &amp;quot;$file&amp;quot; = &amp;quot;$file2&amp;quot; ]]; then  #MIGNOTTA LADRA STRINGA!&lt;br /&gt;
					continue&lt;br /&gt;
				fi&lt;br /&gt;
				filesize2=$(stat -c%s &amp;quot;$file2&amp;quot;)&lt;br /&gt;
				if [[ $filesize -eq $filesize2 ]]; then&lt;br /&gt;
					diff &amp;quot;$file&amp;quot; &amp;quot;$file2&amp;quot; &amp;amp;&amp;amp; echo $file $file2 ###&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
#Purtroppo non siamo riusciti a finire e abbiamo optato per una soluzione poco efficiente con un diff, poi continueremo per rendarlà un po migliore&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=354</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=354"/>
		<updated>2013-11-25T23:26:39Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for filePaths in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        # No files with same size =&amp;gt; No files with same content&lt;br /&gt;
        if len(filePaths) &amp;lt; 2: break&lt;br /&gt;
        PopulateSameContent(filePaths, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(filePaths, sameContent):&lt;br /&gt;
    for filePath in filePaths:&lt;br /&gt;
        md5 = GetMd5Hash(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Get the MD5 hash without loading the whole file to memory&lt;br /&gt;
# Break the file in chunks whose size is a multiple of 128&lt;br /&gt;
# This takes advantage of the fact that MD5 has 128-byte digest blocks&lt;br /&gt;
def GetMd5Hash(filePath, blockSize = 2 ** 20):&lt;br /&gt;
    digest = hashlib.md5()&lt;br /&gt;
    with open(filePath, &amp;quot;rb&amp;quot;) as file:&lt;br /&gt;
        for chunk in iter(lambda: file.read(blockSize), b''): &lt;br /&gt;
            digest.update(chunk)&lt;br /&gt;
    return digest.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print(&amp;quot;Lists of files having same content:&amp;quot;)&lt;br /&gt;
    for files in sorted(sameContent.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2: break&lt;br /&gt;
        print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(file for file in files)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	l1&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
==Bash==&lt;br /&gt;
Qualche idea per Bash...&amp;lt;br/&amp;gt;&lt;br /&gt;
Si potrebbero usare:&amp;lt;br/&amp;gt;&lt;br /&gt;
Per la dimensione in byte dei &amp;lt;file&amp;gt;:&lt;br /&gt;
 fileSize=$(stat --format=%s &amp;lt;file&amp;gt;)&lt;br /&gt;
Per avere l'output del solo hash md5 (senza l'ausilio di altri comandi):&lt;br /&gt;
 fileHashMd5=$(md5sum &amp;lt;file&amp;gt; | while read fileHash fileName; do echo $fileHash; done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Fede&amp;amp;Alessio#&lt;br /&gt;
for file in *; do&lt;br /&gt;
	if [[ -f &amp;quot;$file&amp;quot; ]] ; then&lt;br /&gt;
		filesize=$(stat -c%s &amp;quot;$file&amp;quot;)&lt;br /&gt;
		for file2 in *; do&lt;br /&gt;
			if [[ -f &amp;quot;$file2&amp;quot; ]] ; then&lt;br /&gt;
				if [[ &amp;quot;$file&amp;quot; = &amp;quot;$file2&amp;quot; ]]; then  #MIGNOTTA LADRA STRINGA!&lt;br /&gt;
					continue&lt;br /&gt;
				fi&lt;br /&gt;
				filesize2=$(stat -c%s &amp;quot;$file2&amp;quot;)&lt;br /&gt;
				if [[ $filesize -eq $filesize2 ]]; then&lt;br /&gt;
					diff &amp;quot;$file&amp;quot; &amp;quot;$file2&amp;quot; &amp;amp;&amp;amp; echo $file $file2 ###&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
#Purtroppo non siamo riusciti a finire e abbiamo optato per una soluzione poco efficiente con un diff,&lt;br /&gt;
poi continueremo per rendarlà un po migliore&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=343</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=343"/>
		<updated>2013-11-24T21:12:24Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=342</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=342"/>
		<updated>2013-11-24T21:10:11Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=340</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=340"/>
		<updated>2013-11-24T20:55:04Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h &amp;quot;$2&amp;quot;/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
BornAgainFede &amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=339</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=339"/>
		<updated>2013-11-24T20:48:11Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in $1/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h $2/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h $2/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s &amp;quot;$1&amp;quot;/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede $1/&amp;quot;$bn&amp;quot; $2&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BornAgainFede $1 $2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=338</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=338"/>
		<updated>2013-11-24T20:31:42Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in $1/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h $2/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h $2/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s $1/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s $1/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede $1/&amp;quot;$bn&amp;quot; $2&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BornAgainFede $1 $2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=337</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=337"/>
		<updated>2013-11-24T20:30:20Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in $1/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h $2/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h $2/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s $1/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s $1/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede $1/&amp;quot;$bn$2&amp;quot;&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BornAgainFede $1 $2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=336</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=336"/>
		<updated>2013-11-24T20:28:07Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in $1/*; do&lt;br /&gt;
	bn=$(basename &amp;quot;$f&amp;quot;)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h $2/&amp;quot;$bn&amp;quot; ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h $2/&amp;quot;$bn$i&amp;quot; ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s $1/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn$i&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			ln -s $1/&amp;quot;$bn&amp;quot; $2/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede $1/$bn $2&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BornAgainFede $1 $2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=335</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=335"/>
		<updated>2013-11-24T19:19:50Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in $1/*; do&lt;br /&gt;
	bn=$(basename $f)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h $2/$bn ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h $2/$bn$i ]] ; do&lt;br /&gt;
			let &amp;quot;i += 1&amp;quot; &lt;br /&gt;
			done&lt;br /&gt;
			ln -s $1/$bn $2/$bn$i&lt;br /&gt;
		else&lt;br /&gt;
			ln -s $1/$bn $2/$bn&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede $1/$bn $2&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BornAgainFede $1 $2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=334</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=334"/>
		<updated>2013-11-24T19:02:45Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Ecco la mia versione in bash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in $1/*; do&lt;br /&gt;
	bn=$(basename $f)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h $2/$bn ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h $2/$bn$i ]] ; do&lt;br /&gt;
			i=$i+1&lt;br /&gt;
			done&lt;br /&gt;
			ln -s $1/$bn $2/$bn$i&lt;br /&gt;
		else&lt;br /&gt;
			ln -s $1/$bn $2/$bn&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede $1/$bn $2&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BornAgainFede $1 $2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=333</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=333"/>
		<updated>2013-11-24T19:02:15Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
BornAgainFede () {&lt;br /&gt;
for f in $1/*; do&lt;br /&gt;
	bn=$(basename $f)&lt;br /&gt;
	if [[ -f $f ]] ; then&lt;br /&gt;
		if [[ -h $2/$bn ]] ; then&lt;br /&gt;
			i=1&lt;br /&gt;
			while [[ -h $2/$bn$i ]] ; do&lt;br /&gt;
			i=$i+1&lt;br /&gt;
			done&lt;br /&gt;
			ln -s $1/$bn $2/$bn$i&lt;br /&gt;
		else&lt;br /&gt;
			ln -s $1/$bn $2/$bn&lt;br /&gt;
		fi&lt;br /&gt;
		#ln -s $1/$bn $2/$bn&lt;br /&gt;
	fi&lt;br /&gt;
	if [[ -d $f ]] ; then&lt;br /&gt;
		BornAgainFede $1/$bn $2&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BornAgainFede $1 $2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=322</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=322"/>
		<updated>2013-11-24T09:18:26Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	l1&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=315</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=315"/>
		<updated>2013-11-23T21:13:59Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=314</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=314"/>
		<updated>2013-11-23T21:12:50Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=313</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=313"/>
		<updated>2013-11-23T21:09:28Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=312</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=312"/>
		<updated>2013-11-23T20:38:32Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro la lista&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=311</id>
		<title>ProvaPratica 2013.07.18</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.07.18&amp;diff=311"/>
		<updated>2013-11-23T19:35:02Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file base name - occurrences}&lt;br /&gt;
    nameFreq = { }&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            nameFreq[fileBaseName] = nameFreq.get(fileBaseName, -1) + 1&lt;br /&gt;
            &lt;br /&gt;
            # Create a soft link&lt;br /&gt;
            freq = nameFreq[fileBaseName]&lt;br /&gt;
            linkName = &amp;quot;{0}{1}&amp;quot;.format(fileBaseName, str(freq) if freq &amp;gt; 0 else &amp;quot;&amp;quot;)&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Questa è la mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def collectfiles(arg1,arg2): &lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		B=str(fcd.pop())&lt;br /&gt;
		C='{0}/{1}'.format(arg1,B)&lt;br /&gt;
		if os.path.isdir('{0}'.format(C)):&lt;br /&gt;
			collectfiles(C,arg2)&lt;br /&gt;
		elif os.path.isfile('{0}'.format(C)):&lt;br /&gt;
			try:&lt;br /&gt;
				os.symlink('{0}'.format(C), '{0}/{1}'.format(arg2,B))&lt;br /&gt;
			except OSError:&lt;br /&gt;
				i=1&lt;br /&gt;
				while True:&lt;br /&gt;
					try:&lt;br /&gt;
						os.symlink('{0}'.format(C), '{0}/{1}{2}'.format(arg2,B,i))&lt;br /&gt;
						break&lt;br /&gt;
					except OSError:&lt;br /&gt;
						i=i+1&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	collectfiles(str(sys.argv[1]),str(sys.argv[2]))&lt;br /&gt;
except OSError:&lt;br /&gt;
		print(&amp;quot;Invalid Directory!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Fede&lt;br /&gt;
&lt;br /&gt;
Leggendo la tua versione ho pensato che in effetti se i file sono &amp;quot;&amp;quot;&amp;quot;pochi&amp;quot;&amp;quot;&amp;quot; l'hash-table non e' necessaria. E' sufficiente un controllo iterativo.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
18 luglio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.07.18.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 3:&lt;br /&gt;
        print(&amp;quot;The function requires two arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    srcDir = str(argv[1])&lt;br /&gt;
    dstDir = str(argv[2])&lt;br /&gt;
    if not os.path.isdir(srcDir):&lt;br /&gt;
        print(&amp;quot;First argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    if not os.path.isdir(dstDir):&lt;br /&gt;
        print(&amp;quot;Second argument should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Traverse the directory tree and create a soft link for each file&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(srcDir):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            # 'example.pdf' -&amp;gt; 'example'&lt;br /&gt;
            # 'example.xml' -&amp;gt; 'example'&lt;br /&gt;
            fileBaseName, _ = os.path.splitext(fileName)&lt;br /&gt;
            linkName = fileBaseName&lt;br /&gt;
            srcPath = os.path.join(os.path.abspath(dirPath), fileName)&lt;br /&gt;
            dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            i = 0&lt;br /&gt;
            while os.path.isfile(dstPath):&lt;br /&gt;
                # 'example' will point to 'example.pdf'&lt;br /&gt;
                # 'example1' will point to 'example.xml'&lt;br /&gt;
                i += 1&lt;br /&gt;
                linkName = fileBaseName + str(i)&lt;br /&gt;
                dstPath = os.path.join(dstDir, linkName)&lt;br /&gt;
            if not os.path.lexists(dstPath):&lt;br /&gt;
                os.symlink(srcPath, dstPath)&lt;br /&gt;
        &lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=310</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=310"/>
		<updated>2013-11-23T19:27:45Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro la lista&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=309</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=309"/>
		<updated>2013-11-23T19:17:27Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro la lista&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=308</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=308"/>
		<updated>2013-11-23T19:13:02Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro la lista&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashati&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=307</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=307"/>
		<updated>2013-11-23T19:07:20Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro la lista&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=306</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=306"/>
		<updated>2013-11-23T19:04:57Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1):&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=305</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=305"/>
		<updated>2013-11-23T19:04:08Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file e solo file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1):&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=304</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=304"/>
		<updated>2013-11-23T19:03:07Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file e solo file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario rimuove da key a lista rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1):&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=303</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=303"/>
		<updated>2013-11-23T19:00:45Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file e solo file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario rez[filename]=filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario rimuove da key a lista rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1):&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=302</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=302"/>
		<updated>2013-11-23T19:00:29Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file e solo file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario rez[filename]=filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario rimuove da key a lista rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1):&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=301</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=301"/>
		<updated>2013-11-23T18:59:55Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for files in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2:&lt;br /&gt;
            break&lt;br /&gt;
        PopulateSameContent(files, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, dirNames, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(files, sameContent):&lt;br /&gt;
    for filePath in files:&lt;br /&gt;
        md5 = Md5Checksum(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Compute the MD5 hash of a file&lt;br /&gt;
def Md5Checksum(filePath):&lt;br /&gt;
    with open(filePath, 'rb') as file:&lt;br /&gt;
        m = hashlib.md5()&lt;br /&gt;
        while True:&lt;br /&gt;
            data = file.read(8192)&lt;br /&gt;
            if not data:&lt;br /&gt;
                break&lt;br /&gt;
            m.update(data)&lt;br /&gt;
        return m.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print('List of files having same content:')&lt;br /&gt;
    for list in sameContent.values():&lt;br /&gt;
        if len(list) &amp;gt; 1:&lt;br /&gt;
            print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(str(i) for i in list)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file e solo file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario rez[filename]=filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario rimuove da key a lista rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1):&lt;br /&gt;
	res = []&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: print('{0}   \t e   \t {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
			else:continue&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	obviouslyequal = a.pop(0)&lt;br /&gt;
	print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
	for oe in obviouslyequal:&lt;br /&gt;
		print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\nle seguenti coppie invece contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=288</id>
		<title>ProvaPratica 2013.05.29</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=288"/>
		<updated>2013-11-22T10:56:51Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
29 maggio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.05.29.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 2:&lt;br /&gt;
        print(&amp;quot;The function requires one argument to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    topDir = str(sys.argv[1])&lt;br /&gt;
    if not os.path.isdir(topDir):&lt;br /&gt;
        print(&amp;quot;The parameter should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file extension - total size}&lt;br /&gt;
    extensionSize = { }&lt;br /&gt;
    GetSize(topDir, extensionSize)&lt;br /&gt;
    &lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(extensionSize)&lt;br /&gt;
&lt;br /&gt;
def GetSize(topDir, extensionSize):&lt;br /&gt;
    for dirPath, dirNames, files in os.walk(topDir):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            # 'example.mp3' -&amp;gt; ['example', 'mp3']&lt;br /&gt;
            # 'example.tar.gz' -&amp;gt; ['example', 'tar', 'gz']&lt;br /&gt;
            parts = file.split('.')&lt;br /&gt;
            # ['example', 'mp3'] -&amp;gt; ['mp3']&lt;br /&gt;
            # ['example', 'tar', 'gz'] -&amp;gt; ['tar', 'gz']&lt;br /&gt;
            parts = parts[1:]&lt;br /&gt;
            # ['mp3'] -&amp;gt; '.mp3'&lt;br /&gt;
            # ['tar', 'gz'] -&amp;gt; '.tar.gz'&lt;br /&gt;
            fileExtension = &amp;quot;.{0}&amp;quot;.format(&amp;quot;.&amp;quot;.join(str(part) for part in parts))&lt;br /&gt;
            &lt;br /&gt;
            # Compute the size in Bytes and update the dictionary&lt;br /&gt;
            filePath = os.path.join(dirPath, file)   &lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            extensionSize[fileExtension] = extensionSize.get(fileExtension, 0) + fileSize&lt;br /&gt;
&lt;br /&gt;
# Print results&lt;br /&gt;
def PrintResults(extensionSize):&lt;br /&gt;
    for key, value in sorted(extensionSize.items()):&lt;br /&gt;
        print('{0}: {1} Bytes.'.format(key, value))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, sys, copy&lt;br /&gt;
&lt;br /&gt;
def dotsubstr(a):#restituisce la sottostringa .suffisso&lt;br /&gt;
	#fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	i=0&lt;br /&gt;
	try:&lt;br /&gt;
		while a[i]!='.':&lt;br /&gt;
			i=i+1&lt;br /&gt;
		return a[i:]&lt;br /&gt;
	except IndexError:&lt;br /&gt;
		return -1&lt;br /&gt;
&lt;br /&gt;
def compliarg(li,arg):#restituisce una lista di tutti gli elementi contenenti la sottostringa arg come suffisso&lt;br /&gt;
	res=[]&lt;br /&gt;
	while li != []:&lt;br /&gt;
		a=li.pop()&lt;br /&gt;
		if a.endswith(arg): res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listremintsect(l2,l1):#restituisce una lista res = l1 - intersezione di l1 ed l2&lt;br /&gt;
	res=[]&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		a=l1.pop()&lt;br /&gt;
		if not a in l2: res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def createpathlist(c,path):#restituisce una lista di path 'path' relativi ai file contenuti in c.&lt;br /&gt;
	res = []&lt;br /&gt;
	while c != []:&lt;br /&gt;
		res.append('{0}/{1}'.format(path,c.pop()))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def totsizes(d): #data una lista d di path restituisce la somma di tutti i size di d&lt;br /&gt;
	res = 0&lt;br /&gt;
	while d != []:&lt;br /&gt;
		a = d.pop()&lt;br /&gt;
		if os.path.isfile('{0}'.format(a)):&lt;br /&gt;
			res = res + os.path.getsize('{0}'.format(a))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listsubstr(arg): #ritorna un dizionario del tipo diz[str(suffisso)] = int(size relativo al suffisso)&lt;br /&gt;
	res = {}&lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		fcdtmp=copy.deepcopy(fcd) #BUGGONE SENZA COPY!!!!!!&lt;br /&gt;
		a = fcd.pop()&lt;br /&gt;
		b = dotsubstr(a)&lt;br /&gt;
		if b == -1: continue&lt;br /&gt;
		else: pass&lt;br /&gt;
		c = compliarg(fcdtmp,b)&lt;br /&gt;
		s=copy.deepcopy(c) #!!!!!!!!!!!!!!!!!!!!!!!!!&lt;br /&gt;
		d = createpathlist(c,arg)&lt;br /&gt;
		res[b] = totsizes(d)&lt;br /&gt;
&lt;br /&gt;
		fcd = listremintsect(s,fcd)&lt;br /&gt;
&lt;br /&gt;
	return res&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	res = listsubstr(sys.argv[1])&lt;br /&gt;
	a=list(res.keys())&lt;br /&gt;
	while a != []:&lt;br /&gt;
		b = a.pop()&lt;br /&gt;
		print('{0}:\t{1}'.format(b,res[b]))&lt;br /&gt;
except OSError:&lt;br /&gt;
	print(&amp;quot;Could not solve path&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=287</id>
		<title>ProvaPratica 2013.05.29</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=287"/>
		<updated>2013-11-22T10:27:22Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
29 maggio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.05.29.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 2:&lt;br /&gt;
        print(&amp;quot;The function requires one argument to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    topDir = str(sys.argv[1])&lt;br /&gt;
    if not os.path.isdir(topDir):&lt;br /&gt;
        print(&amp;quot;The parameter should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file extension - total size}&lt;br /&gt;
    extensionSize = { }&lt;br /&gt;
    GetSize(topDir, extensionSize)&lt;br /&gt;
    &lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(extensionSize)&lt;br /&gt;
&lt;br /&gt;
def GetSize(topDir, extensionSize):&lt;br /&gt;
    for dirPath, dirNames, files in os.walk(topDir):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            # 'example.mp3' -&amp;gt; ['example', 'mp3']&lt;br /&gt;
            # 'example.tar.gz' -&amp;gt; ['example', 'tar', 'gz']&lt;br /&gt;
            parts = file.split('.')&lt;br /&gt;
            # ['example', 'mp3'] -&amp;gt; ['mp3']&lt;br /&gt;
            # ['example', 'tar', 'gz'] -&amp;gt; ['tar', 'gz']&lt;br /&gt;
            parts = parts[1:]&lt;br /&gt;
            # ['mp3'] -&amp;gt; '.mp3'&lt;br /&gt;
            # ['tar', 'gz'] -&amp;gt; '.tar.gz'&lt;br /&gt;
            fileExtension = &amp;quot;.{0}&amp;quot;.format(&amp;quot;.&amp;quot;.join(str(part) for part in parts))&lt;br /&gt;
            &lt;br /&gt;
            # Compute the size in Bytes and update the dictionary&lt;br /&gt;
            filePath = os.path.join(dirPath, file)   &lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            extensionSize[fileExtension] = extensionSize.get(fileExtension, 0) + fileSize&lt;br /&gt;
&lt;br /&gt;
# Print results&lt;br /&gt;
def PrintResults(extensionSize):&lt;br /&gt;
    for key, value in sorted(extensionSize.items()):&lt;br /&gt;
        print('{0}: {1} Bytes.'.format(key, value))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, sys, copy&lt;br /&gt;
&lt;br /&gt;
def dotsubstr(a):#restituisce la sottostringa .suffisso&lt;br /&gt;
	#fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	i=0&lt;br /&gt;
	try:&lt;br /&gt;
		while a[i]!='.':&lt;br /&gt;
			i=i+1&lt;br /&gt;
		return a[i:]&lt;br /&gt;
	except IndexError:&lt;br /&gt;
		return -1&lt;br /&gt;
&lt;br /&gt;
def compliarg(li,arg):#restituisce una lista di tutti gli elementi contenenti la sottostringa arg come suffisso&lt;br /&gt;
	res=[]&lt;br /&gt;
	while li != []:&lt;br /&gt;
		a=li.pop()&lt;br /&gt;
		if a.endswith(arg): res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listremintsect(l2,l1):#restituisce una lista res = l1 - intersezione di l1 ed l2&lt;br /&gt;
	res=[]&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		a=l1.pop()&lt;br /&gt;
		if not a in l2: res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def createpathlist(c,path):#restituisce una lista di path 'path' relativi ai file contenuti in c.&lt;br /&gt;
	res = []&lt;br /&gt;
	while c != []:&lt;br /&gt;
		res.append('{0}/{1}'.format(path,c.pop()))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def totsizes(d): #data una lista d di path restituisce la somma di tutti i size di d&lt;br /&gt;
	res = 0&lt;br /&gt;
	while d != []:&lt;br /&gt;
		res = res + os.path.getsize('{0}'.format(d.pop()))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listsubstr(arg): #ritorna un dizionario del tipo diz[str(suffisso)] = int(size relativo al suffisso)&lt;br /&gt;
	res = {}&lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		fcdtmp=copy.deepcopy(fcd) #BUGGONE SENZA COPY!!!!!!&lt;br /&gt;
		a = fcd.pop()&lt;br /&gt;
		b = dotsubstr(a)&lt;br /&gt;
		if b == -1: continue&lt;br /&gt;
		else: pass&lt;br /&gt;
		c = compliarg(fcdtmp,b)&lt;br /&gt;
		s=copy.deepcopy(c) #!!!!!!!!!!!!!!!!!!!!!!!!!&lt;br /&gt;
		d = createpathlist(c,arg)&lt;br /&gt;
		res[b] = totsizes(d)&lt;br /&gt;
&lt;br /&gt;
		fcd = listremintsect(s,fcd)&lt;br /&gt;
&lt;br /&gt;
	return res&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	res = listsubstr(sys.argv[1])&lt;br /&gt;
	a=list(res.keys())&lt;br /&gt;
	while a != []:&lt;br /&gt;
		b = a.pop()&lt;br /&gt;
		print('{0}:\t{1}'.format(b,res[b]))&lt;br /&gt;
except OSError:&lt;br /&gt;
	print(&amp;quot;Could not solve path&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=286</id>
		<title>ProvaPratica 2013.05.29</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.05.29&amp;diff=286"/>
		<updated>2013-11-22T10:26:45Z</updated>

		<summary type="html">&lt;p&gt;Fede: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
29 maggio 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.05.29.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 2:&lt;br /&gt;
        print(&amp;quot;The function requires one argument to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Check parameters&lt;br /&gt;
    topDir = str(sys.argv[1])&lt;br /&gt;
    if not os.path.isdir(topDir):&lt;br /&gt;
        print(&amp;quot;The parameter should be an existing directory.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file extension - total size}&lt;br /&gt;
    extensionSize = { }&lt;br /&gt;
    GetSize(topDir, extensionSize)&lt;br /&gt;
    &lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(extensionSize)&lt;br /&gt;
&lt;br /&gt;
def GetSize(topDir, extensionSize):&lt;br /&gt;
    for dirPath, dirNames, files in os.walk(topDir):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            # 'example.mp3' -&amp;gt; ['example', 'mp3']&lt;br /&gt;
            # 'example.tar.gz' -&amp;gt; ['example', 'tar', 'gz']&lt;br /&gt;
            parts = file.split('.')&lt;br /&gt;
            # ['example', 'mp3'] -&amp;gt; ['mp3']&lt;br /&gt;
            # ['example', 'tar', 'gz'] -&amp;gt; ['tar', 'gz']&lt;br /&gt;
            parts = parts[1:]&lt;br /&gt;
            # ['mp3'] -&amp;gt; '.mp3'&lt;br /&gt;
            # ['tar', 'gz'] -&amp;gt; '.tar.gz'&lt;br /&gt;
            fileExtension = &amp;quot;.{0}&amp;quot;.format(&amp;quot;.&amp;quot;.join(str(part) for part in parts))&lt;br /&gt;
            &lt;br /&gt;
            # Compute the size in Bytes and update the dictionary&lt;br /&gt;
            filePath = os.path.join(dirPath, file)   &lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            extensionSize[fileExtension] = extensionSize.get(fileExtension, 0) + fileSize&lt;br /&gt;
&lt;br /&gt;
# Print results&lt;br /&gt;
def PrintResults(extensionSize):&lt;br /&gt;
    for key, value in sorted(extensionSize.items()):&lt;br /&gt;
        print('{0}: {1} Bytes.'.format(key, value))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
mia versione&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, sys, copy&lt;br /&gt;
&lt;br /&gt;
def dotsubstr(a):#restituisce la sottostringa .suffisso&lt;br /&gt;
	#fcd = os.listdir('{0}'.format(arg1))&lt;br /&gt;
	i=0&lt;br /&gt;
	try:&lt;br /&gt;
		while a[i]!='.':&lt;br /&gt;
			i=i+1&lt;br /&gt;
		return a[i:]&lt;br /&gt;
	except IndexError:&lt;br /&gt;
		return -1&lt;br /&gt;
&lt;br /&gt;
def compliarg(li,arg):#restituisce una lista di tutti gli elementi contenenti la sottostringa arg come suffisso&lt;br /&gt;
	res=[]&lt;br /&gt;
	while li != []:&lt;br /&gt;
		a=li.pop()&lt;br /&gt;
		if a.endswith(arg): res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listremintsect(l2,l1):#restituisce una lista res = l1 - intersezione di l1 ed l2&lt;br /&gt;
	res=[]&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		a=l1.pop()&lt;br /&gt;
		if not a in l2: res.append(a)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def createpathlist(c,path):#restituisce una lista di path 'path' relativi ai file contenuti in c.&lt;br /&gt;
	res = []&lt;br /&gt;
	while c != []:&lt;br /&gt;
		res.append('{0}/{1}'.format(path,c.pop()))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def totsizes(d): #data una lista d di path restituisce la somma di tutti i size di d&lt;br /&gt;
	res = 0&lt;br /&gt;
	while d != []:&lt;br /&gt;
		res = res + os.path.getsize('{0}'.format(d.pop()))&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def listsubstr(arg): #ritorna un dizionario del tipo diz[str(suffisso)] = int(size relativo al suffisso)&lt;br /&gt;
	res = {}&lt;br /&gt;
	fcd = os.listdir('{0}'.format(arg))&lt;br /&gt;
	while fcd != []:&lt;br /&gt;
		fcdtmp=copy.deepcopy(fcd) #BUGGONE SENZA COPY!!!!!!&lt;br /&gt;
		a = fcd.pop()&lt;br /&gt;
		b = dotsubstr(a)&lt;br /&gt;
		if b == -1: continue&lt;br /&gt;
		else: pass&lt;br /&gt;
		c = compliarg(fcdtmp,b)&lt;br /&gt;
		s=copy.deepcopy(c) #!!!!!!!!!!!!!!!!!!!!!!!!!&lt;br /&gt;
		d = createpathlist(c,arg)&lt;br /&gt;
		res[b] = totsizes(d)&lt;br /&gt;
&lt;br /&gt;
		fcd = listremintsect(s,fcd)&lt;br /&gt;
&lt;br /&gt;
	return res&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
	res = listsubstr(sys.argv[1])&lt;br /&gt;
	a=list(res.keys())&lt;br /&gt;
	while a != []:&lt;br /&gt;
		b = a.pop()&lt;br /&gt;
		print('{0}:\t{1}'.format(b,res[b]))&lt;br /&gt;
except OSError:&lt;br /&gt;
	print(&amp;quot;Could not solve path&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;/div&gt;</summary>
		<author><name>Fede</name></author>
	</entry>
</feed>