-
Notifications
You must be signed in to change notification settings - Fork 5
/
Relocate.pl
61 lines (51 loc) · 1.64 KB
/
Relocate.pl
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
#!/usr/bin/perl
use strict;
print "MPIDE Library Relocator v0.1\n";
print "brian\@pontech.com\n\n";
use File::HomeDir;
use File::Basename;
use File::Copy;
my $sourceDir = dirname($0);
my $baseName = basename($0);
my $homeDir = File::HomeDir->my_home;
my $destinationDir = "$homeDir\\Workspace\\Mpide\\libraries";
my $stateFile = "DO_NOT_COMMIT.txt";
#print dir($sourceDir);
print "S: ", $sourceDir, "\n";
print "D: ", $destinationDir, "\n";
print "\n\n";
unless($baseName eq "Relocate.pl") {
print "Basename Mismatch\n";
}
else {
if(-e $stateFile) {
print "D -> S\n";
open(FILE, "$stateFile");
while(<FILE>) {
chomp;
my $fileName = basename($_);
# print "mv $_ $sourceDir\\$fileName\n";
move($_, "$sourceDir\\$fileName");
rmdir(dirname($_));
}
close(FILE);
unlink $stateFile;
}
else {
print "S -> D\n";
open(FILE, ">>$stateFile");
opendir(my $dh, $sourceDir) || die "can't opendir $sourceDir: $!";
my @files = grep(/\.h$/, readdir($dh));
closedir($dh);
foreach my $fileName(@files) {
(my $sansExtension = $fileName) =~ s/\.[^.]+$//;
mkdir "$destinationDir\\$sansExtension", 0755;
# print "mv $sourceDir\\$fileName $destinationDir\\$sansExtension\\$fileName\n";
move("$sourceDir\\$fileName", "$destinationDir\\$sansExtension\\$fileName");
print FILE "$destinationDir\\$sansExtension\\$fileName\n";
}
close(FILE);
}
}
#print "\n<Press Enter to Close>\n";
#<STDIN>;