updated git and svn scripts
[xrzperl.git] / xrmdir
blobc90a60d9560414841b25a9615558814e4530a0e0
1 #!/usr/bin/perl -w
2 ###APPNAME: xrmdir
3 ###APPAUTHOR: geek
4 ###APPDATE: Sat Sep 29 15:37:45 2007
5 ###APPVER: 0.1
6 ###APPDESC: delete directories which even not empty
7 ###APPUSAGE: [options] (directories...)
8 ###APPEXAMPLE: xrmdir -g tmp Temp
9 ###APPOPTION: s:Silent Mode|g:Gui Mode
10 use strict;
11 $ARGV[0]="-h" unless(@ARGV);
12 foreach(@ARGV){
13 exit(system("formathelp",$0)) if($_ eq "-h" || $_ eq "--help");
16 my $silent=0;
17 my $gui=0;
19 sub DeleteFolder {
20 system("rm","-fdr",@_);
23 sub Message {
24 return if($silent);
25 my $msg=join(" ",@_);
26 if($gui) {
27 system("zenity","--info","--text=$msg");
29 else {
30 print($msg);
34 sub Confirm {
35 return if($silent);
36 my $msg=join(" ",@_);
37 if($gui) {
38 if (system("zenity","-question","-text=$msg")) {
39 return 0;
41 else {
42 return 1;
45 else {
46 my $ans;
47 print($msg,"(y/n)");
48 read STDIN,$ans,1
49 if(lc($ans) eq "y") {
50 return 1;
52 else {
53 return 0;
59 if [ -z "$OPT_Silent" ] ; then
60 DeleteFolder "$D" 2>/dev/null 1>/dev/null
61 else
62 if [ ! -d "$D" ] ; then
63 Message "\"$D\" not exists."
64 else
65 if Confirm "Delete \"$D\"?" ; then
66 DeleteFolder "$D"
71 if Confirm "Delete " "$@" "\nContinue?" ; then
72 for D in "$@" ; do
73 [ "$D" == "-s" -o "$D" == "-g" ] && continue
74 if [ ! -d "$D" ] ; then
75 Message "\"$D\" not exists."
76 else
77 DeleteFolder "$D"
79 done