Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 变量文件名的Tcl正则表达式_Regex_File_Variables_Directory_Tcl - Fatal编程技术网

Regex 变量文件名的Tcl正则表达式

Regex 变量文件名的Tcl正则表达式,regex,file,variables,directory,tcl,Regex,File,Variables,Directory,Tcl,希望使我的Directorypath灵活地在tcl中运行脚本。路径总是相同的,只是像“V1”这样的端点不同。可能它与正则表达式一起工作(例如C:/Users/testuser/Desktop/testcl/*.dat) 是否可以扫描目录中的所有.dat文件并运行一个具有所有可能的脚本?您需要使用glob命令。它返回一个文件名列表,您可以使用foreach(或您喜欢的任何其他内容;它是一个普通的旧列表)对其进行迭代。您可以给出一个模式,-directory选项使这一切变得非常简单。在这里看看这个:

希望使我的Directorypath灵活地在tcl中运行脚本。路径总是相同的,只是像“V1”这样的端点不同。可能它与正则表达式一起工作(例如C:/Users/testuser/Desktop/testcl/*.dat)


是否可以扫描目录中的所有.dat文件并运行一个具有所有可能的脚本?

您需要使用
glob
命令。它返回一个文件名列表,您可以使用
foreach
(或您喜欢的任何其他内容;它是一个普通的旧列表)对其进行迭代。您可以给出一个模式,
-directory
选项使这一切变得非常简单。在这里看看这个:

set dir "C:/Users/testuser/Desktop/TempTCL"
foreach filename [glob -directory $dir *.dat] {
    puts "I found a file called $filename"
}
更改处理代码的正文(在
$filename
中使用方便的完整文件名),工作就完成了

set dir "C:/Users/testuser/Desktop/TempTCL"
foreach filename [glob -directory $dir *.dat] {
    puts "I found a file called $filename"
}