期待,找到带有时间戳的文件

时间:2015-05-18 15:36:15

标签: tcl expect

我的文件夹如下:

RBS_delete20150518-170641.xml
RBS_delete20150517-160545.xml
...

我使用expect程序,但无法使用正则表达式处理日期戳:

if {[file exists /home/ARNE/ARNE/SCRIPTS/RBS_delete[0-9].xml]}

1 个答案:

答案 0 :(得分:2)

file exists不支持regexp模式。您可以使用glob

set myfiles [ glob -nocomplain "/home/ARNE/ARNE/SCRIPTS/*.xml" ]
if {[llength $myfiles]!=0} {
puts "Following XML files found  : "
foreach fname $myfiles {
    puts $fname; # Now you can process these elements as per your wish
    if {[regexp {RBS_delete\d+\-\d+\.xml} $fname]} {
        puts " file name pattern matched"
    }
}
} else {
puts "No XML files available"
}