如何在tcl中搜索和打印realpath版本? [英] how to seach and print realpath version in tcl?

查看:44
本文介绍了如何在tcl中搜索和打印realpath版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设路径 x/y/z 有 5 个目录,即 1.1、1.2、1.3、1.4、1.5.现在我只想打印大于 1.1 的目录名称.如果在另一个路径 a/b/c 中存在相同的目录,但缺​​少 1.2 目录,那么它应该打印 1.3,因为下一个目录高于 1.1?如何在 tclsh 中做到这一点???

Suppose a path x/y/z has 5 directories i.e 1.1,1.2,1.3,1.4,1.5. now I want to print only that directories names which is greater than 1.1. if in another path a/b/c same directories is present, but 1.2 dir is missing, then it should print 1.3 as the next directory is higher than 1.1? How to do that in tclsh???

推荐答案

我猜你是在谈论文件名?目录?

I assume you're talking about filenames here? Of directories?

要获取某个位置中与此类模式匹配的目录列表,您可以使用:

To get a list of directories in a location that match a pattern like that, you might use:

# d for "directory"
set names [glob -directory a/b/c -type d {[0-9]*.[0-9]*}]

这将是随机顺序(嗯,这取决于操作系统中的大量因素,因此假装它是随机的要简单得多!)并且可能其中有一些误报.我们需要过滤和排序.幸运的是,我们有package vsatisfies 来进行解析.

That's going to be in random order (well, it depends on a vast number of factors in the OS so pretending it is random is much simpler!) and might have some false positives in it. We need to filter and sort. Fortunately, we have package vsatisfies to do the parsing.

set filtered [lmap name $names {
    try {
        if {[package vsatisfies [file tail $name] 1.1]} {
            set name
        } else continue
    } on error {} continue
}]
# You'll find that dictionary sorting does the Right Thing in this case
set sorted [lsort -dictionary $filtered]

现在剩下的就是打印出列表中的元素.其中最大的项是 [lindex $sorted end]...

All that's left now is to print the elements in the list out. The maximum item in it is [lindex $sorted end]

这篇关于如何在tcl中搜索和打印realpath版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆