-
Notifications
You must be signed in to change notification settings - Fork 15
/
createTestDummyFolder
executable file
·82 lines (67 loc) · 1.67 KB
/
createTestDummyFolder
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/perl
use 5.014;
use autodie;
#use LWP::Simple;
use Web::Query;
use JSON;
use utf8;
use Encode;
use DBI;
use Data::Dumper;
use File::Copy;
use File::Basename;
use File::Find ();
use open ":encoding(utf8)";
binmode(STDIN, ':encoding(utf8)');
binmode(STDOUT, ':encoding(utf8)');
binmode(STDERR, ':encoding(utf8)');
my $target = $ARGV[0];
$target .= '/' if( substr($target, -1) ne '/');
my $destDir = $ARGV[1];
#global @all_file = ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
our @all_file;
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, $target);
sub wanted {
# /^.*RJ.*\z/s
# && save_addr($name);
save_addr($name);
}
sub save_addr {
Encode::_utf8_on($_[0]);
# print $_[0] . "\n";
@all_file = ( @all_file, $_[0] );
1;
}
#print Dumper(@all_file);
shift @all_file;
chdir $destDir or die 'chdir fail';
mkdir "dummy", 0755 or warn "mkdir dummy fail: $!";
say '----------- dir ------------';
foreach (@all_file ){
if( -d $_){
my $new_file = $_;
$new_file =~ s#^.*$target#./dummy/# ;
say $new_file;
mkdir "$new_file", 0755 or warn "mkdir $new_file fail: $!";
}
}
say '----------- file ------------';
foreach (@all_file ){
if( ! -d $_){
my $new_file = $_;
$new_file =~ s#^.*$target#./dummy/# ;
$new_file =~ s/"/\\"/g;
my $command = 'touch "'. $new_file .'"';
say $command;
system($command);
}
}