Es soll später mal ein Programm zur Indexierung werden. Dazu habe ich ein Skript geschrieben was Datei- und Verzeichnisnamen nach Doppelungen prüft. Aber das sog. "Optimizing" dauert extrem lange. Bei 11060 Dateien ca. 1 Minute.

Prüft es selbst und sagt mir ob man es optimieren kann.

Code:
#!/usr/bin/perl

$dir = $ARGV[0];

if (!$dir || $dir eq ".") {
	$dir = ".";
	$pwd = `pwd`;
	chomp $pwd;
	@output = split(/\//,$pwd);
	for $object (@output) {
		$object =~ s/\n//g;
		$object =~ s/\///g;
		AddDir ($object) if($object);
	}
}
$command = "ls -ARmQ $dir";
open DIR, "$command |";
while (<DIR>) {
	@output = split(/, /,$_) if ($_);
	CheckOutput (@output);
	#print @output, "\n";
}
#print @output;
sub CheckOutput {
	my @output = @_;
	for $object (@output) {
		# print "original $object\n";
		$object =~ s/\"//g;
		$object =~ s/\n//g;
		if ($object =~ /\:$/) {
			$object =~ s/\:$//g;
			$currentdir = $object;
			$currentdir =~ s/^\.//;
			$currentdir =~ s/^\///;
			if ($currentdir) {
				$currentdir = $pwd . "/" . $currentdir;
			} else {
				$currentdir = $pwd;
			}
			#print "scanning $currentdir\n";
			next;
		} else {
			if ($object) {
				$done = $currentdir ."/". $object ;
			} else {
				next;
			}
		}
		#print "testing \"$object\" ";
		if (-d $done) {
		#	print "1\n";
			# Prüft, ob sich das Verzeichnis bereits in der Liste befindet
			#$dir_id = TestDir ($object);
			#if ($dir_id < 1) {
				# Wenn nicht, wird es hinzugefügt und mit einer Nummer versehen
				$dir_id = AddDir ($object);
			#}
		} elsif ($object) {
		#	print "0\n";
			#$file_id = TestFile ($object);
			#if ($file_id < 1) {
				# Wenn nicht, wird es hinzugefügt und mit einer Nummer versehen
				$file_id = AddFile ($object);
			#}
		}
	}
}
#print "dirs: @directories \n";
#print "files: @files \n";
$totals_dir = $#directories + 1;
$totals_file = $#files + 1;
print "I have found $totals_dir directories and $totals_file files.\n";

print "optimizing...\n";
Optimizing();
$totals_diff_dir = $#diff_directories + 1;
$totals_diff_file = $#diff_files + 1;
print "There are $totals_diff_dir different named directories and $totals_diff_file files.\n";

sub Optimizing {
	for $dir (@directories) {
		if (TestDir($dir) < 1) {
			push @diff_directories, $dir;
		}
	}
	for $file (@files) {
		if (TestFile($file) < 1) {
			push @diff_files, $file;
		}
	}
}

sub TestDir {
	my ($dir) = @_;
	my $value = 0;
	for ($s = 0; $s < $#diff_directories; $s++) {
		if ($dir eq $diff_directories[$s]) {
			$value = $s;
			next;
		}
	}
	return $value;
}

sub AddDir {
	my ($dir) = @_;
	push @directories, $dir;
	return $#directories;
}

sub TestFile {
	my ($file) = @_;
	my $value = 0;
	for ($s = 0; $s < $#diff_files; $s++) {
		if ($file eq $diff_files[$s]) {
			$value = $s;
			next;
		}
	}
	return $value;
}

sub AddFile {
	my ($file) = @_;
	push @files, $file;
	return $#files;
}