Leser: 1
|< 1 2 >| | 11 Einträge, 2 Seiten |
1 2 3 4 5 6 7 8 9
#!/usr/bin/perl use File::Copy; foreach my $file (glob '*.txt') { if (-M $file > 3) { move($file, '\\archiv\\' . $file) or warn "$file: $!"; } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl -w
use File::Find;
my %files;
find(\&todo, ".");
sub todo
{
my $wd = `pwd`;
chomp($wd);
my @lst = lstat;
if((-f) # normal file
&& (not -l) # and not a symbolic link
&& ($lst[3] == 1) # number of hard links == 1
&& ($lst[7] > 0) # size > 0
)
{
$_ =~ s/\'/\'\\\'\'/g;
print "file: \'$_\'\n";
my @md5sum = `md5sum \'$_\'`;
$md5sum = $md5sum[0];
chomp $md5sum;
$md5sum =~ s/(.{32}).*/$1/;
cont:
if(exists $files{$md5sum})
{
if(system "cmp -s \'$files{$md5sum}[0]->{'name'}\' \'$_\'")
{
$md5sum = $md5sum . "_";
goto cont;
}
}
my %tmp;
$tmp{'path'} = $wd;
$tmp{'file'} = $_;
$tmp{'name'} = $wd. "/" .$_;
push @{$files{$md5sum}}, \%tmp;
}
}
foreach(keys %files)
{
if($#{$files{$_}})
{
my $num = $#{$files{$_}} + 1;
my $file_1 = ${$files{$_}}[-1]->{'name'};
my $container_dir = "/cygdrive/r/prjshare/fo00bc/container/$_";
my $container = "$container_dir/${$files{$_}}[-1]->{'file'}";
print("\n\n# +++ file: \"$file_1\" exists $num times\n");
print("mkdir -p \'$container_dir\'\n");
print("\n# bewege\"$file_1\" in container\n\n");
print("mv \'$file_1\' \'$container\'\n");
foreach(@{$files{$_}})
{
print "#\tfile: $_->{'name'}\n";
print "rm -f \'$_->{'name'}\'\n";
print "ln -s \'$container\' \'$_->{'name'}\'\n";
}
}
else
{
# it's a unique file
}
}
|< 1 2 >| | 11 Einträge, 2 Seiten |