没办法,高手都跑到这里来了--Tcl写的脚本的问题--rm \无法删除"(N001"做文件名的文件。请各位大侠不吝指点一二。
#!/usr/local/bin/expect --
########################################################################
# Check command line
########################################################################
if { $argc < 2 } {
send_user "Usage: $argv0 <target> <file/directory> \[file/directory\] ...\n"
exit 1
}
set target [lindex $argv 0]
set paths [lrange $argv 1 end]
########################################################################
# Function: rmr_whatisit
#
# Description: Determines if the specified path exists, and returns
# 0 if path is a directory, 1 if path is file, -1 if
# path does not exist
########################################################################
proc rmr_whatisit { path } {
set matchidx [string last "/" $path]
if { $matchidx == -1 } {
set parentpath /hd0
} else {
set parentpath /hd0/[string range $path 0 [expr { $matchidx - 1 }]]
}
set pname [string toupper [string range $path [expr { $matchidx + 1 }] end]]
send "ll \"$parentpath\"\n"
set retval -1
expect {
-re ":.. $pname\[^\r\n\]+DIR\[^\r\n\]*\n\r" { set retval 0 ; exp_continue }
-re ":.. $pname\[^\r\n\]*\n\r" { set retval 1 ; exp_continue }
-gl "->" {}
timeout { send_user "timeout in rmr_whatisit\n" ; exit 1 }
}
return $retval
}
########################################################################
# Function: rmr_getlist
#
# Description: Returns a list of files in a directory. The list is
# empty if the directory is empty
########################################################################
proc rmr_getlist { path } {
send "ll \"/hd0/$path\"\n"
set retval {}
expect {
-re ":.. \[A-Z_0-9\]+\[.A-Z_0-9\]* " {
lappend retval [string trim [string range $expect_out(0,string) 6 end]]
exp_continue
}
-gl "->" {}
timeout { send_user "timeout in rmr_getlist\n" ; exit 1 }
}
return $retval
}
########################################################################
# Function: rmr_hdpath
#
# Description: Recursively remove file or directory
########################################################################
proc rmr_hdpath { path keepit } {
set type [rmr_whatisit $path];
if { $type == -1 } { ;# path does not exist
send_user "/hd0/$path: no such path\n"
return
} elseif { $type == 0 } { ;# path is a directory
set subpaths [rmr_getlist $path]
foreach subp $subpaths {
rmr_hdpath $path/$subp 0
}
if { $keepit == 0 } {
send "rmdir \"/hd0/$path\"\n"
expect -gl "->" {} timeout { exit 1 }
}
} else { ;# path is a file
if { $keepit == 0 } {
send "remove \"/hd0/$path\"\n"
expect -gl "->" {} timeout { exit 1 }
}
}
}
########################################################################
# Remove all specified paths recursively
########################################################################
spawn telnet $target
expect "*unknown*" { exit 1 } -gl "->" {} timeout { exit 1 }
set keepflag 0
foreach path $paths {
if { $path == "-k" } {
set keepflag 0
continue
}
if { $path == "+k" } {
set keepflag 1
continue
}
rmr_hdpath $path $keepflag
}
send "logout\n"
close
exit 0
现在某目录下除正常文件名外,还有(N001和(N002的文件,无法删除。如何在程序中改动呢?请各位大侠指点。谢谢,还请给出用rm \ 不成功的原因。再谢谢!