initiele import

This commit is contained in:
Ward Wouts 2001-07-31 08:40:13 +00:00
commit d92c3e0f4b

63
mvwrap/mvwrap Executable file
View file

@ -0,0 +1,63 @@
#!/usr/bin/perl -w
#
# Scriptje om vi op de inhoud van directories los te laten
# Makkelijker dan 6000 keer move met de hand doen
# (C) 2001 Ward Wouts
#
use IO::File;
use File::Copy;
use POSIX qw(tmpnam);
$DEBUG = 0;
#Read current dir
opendir(DIRHANDLE, ".") or die "couldn't open .: $!";
while ( defined ($filename = readdir(DIRHANDLE)) ) {
if ($DEBUG) { print "Inside . is something called $filename\n"; }
push @dir, "$filename\n";
}
closedir(DIRHANDLE);
@source= sort @dir;
if ($DEBUG) { print @source; }
# make tempfiles and install handler to remove them
do { $target_name = tmpnam() }
until $target = IO::File->new($target_name, O_RDWR|O_CREAT|O_EXCL);
END { unlink($target_name) or die "Couldn't unlink $target_name: $!" }
foreach (@source) {
print $target $_;
}
close ($target);
@vi = ("vi", "$target_name");
system(@vi) == 0
or die "System @vi failed: $?";
open $target, $target_name;
while (<$target>) {
push @target, $_;
}
close ($target);
if ($DEBUG) { print @target; }
unless ( scalar(@source) == scalar(@target) ) {
die "source and target don't have the same number of lines";
}
$i=0;
while ( $i < scalar(@source) ) {
$source=$source[$i];
chomp($source);
$target=$target[$i];
chomp($target);
unless ( $source eq $target ) {
if ($DEBUG) { print "mv $source $target\n"; }
move("$source", "$target")
or die "move failed: $!";
}
$i++;
}