2 ###APPNAME: zim-add-directory
4 ###APPDATE: 2008-05-11 14:27:04
6 ###APPDESC: add a directory entry to a zim txt file
7 ###APPUSAGE: [--test] (directory) [level]
8 #[entry Name] [entry Description] [destination]
9 ###APPEXAMPLE: zim-add-directory Test .test abc.txt
10 ###APPOPTION: --test:No writing will be made
13 #ENV variable MUST be defined somewhere,
14 #FOR perl to search modules from,
17 use lib
$ENV{XR_PERL_MODULE_DIR
};
19 use MyPlace
::Script
::Usage qw
/help_required help_even_empty/;
20 exit 0 if(help_even_empty
($0,@ARGV));
24 if($ARGV[0] eq "--test") {
28 my ($root_d,$level) = @ARGV;
30 #my ($edir,$ename,$edesc,$dist) = @ARGV;
34 print STDERR
"\t$str";
41 # $ename =~ s/^.*\///g;
46 ## $eloc =~ s/[ ,\+ ~×]/_/g;
52 # $dist =~ s/\/?$/.txt/;
57 warn "Can't change to $dir!\n";
60 sub writeDirectory
($) {
70 chdir($edir) or return(error_chdir
($edir));
71 foreach my $file (glob("*")) {
72 next if($file eq ".");
73 next if($file eq "..");
74 if(-d
$file && $level>=0) {
78 next unless($file =~ /\.txt$/);
85 chdir($olddir) or return(error_chdir
($olddir));
86 print STDERR
"Writing $edir.txt...\n";
88 open FO
,">","/dev/null";
91 open FO
,">","$edir.txt";
93 print FO tee
("=" x
6 . " " . $ename . " " . "=" x
6 . "\n");
94 print FO tee
(scalar(localtime()) . "\n\n");
96 print FO tee
("File list:\n");
97 foreach my $file(@files) {
98 print FO tee
("* [[.$file|$file]]\n");
103 print FO tee
("Directory list:\n");
104 foreach my $dir(@dirs) {
105 print FO tee
("* [[.$dir|<$dir>]]\n");
110 chdir($edir) or return(error_chdir
($edir));
116 chdir($olddir) or return(error_chdir
($olddir));
119 &writeDirectory
($root_d);