Tcl +检查文件存在 [英] Tcl + Check file existance

查看:5252
本文介绍了Tcl +检查文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检查文件是否存在或不在Tcl,但我似乎无法得到一个真实的结果。即使我知道它是存在的。

  while {true} {

if {[文件存在$ file_name] == 1} {
exp_sendcopy file.txt destination \r
putsFile copied!


puts文件不被复制

}

我总是执行File not copied行。我做了一个放$ [文件存在$文件名] ,我总是以0结束。但我知道这个文件存在于当前目录。任何建议吗?

编辑:



另一种方法,我想追求,是当我做一个 dir 使用tcl脚本。我将得到目录中所有文件的输出。我只需要匹配我的文件与输出的列表,并满足如果发现匹配...



我从位置A执行脚本,但使用脚本telnet到位置B.当我做一个文件存在时,它检查位置A本身。这是我的问题...因为我需要在位置B搜索...

解决方案文件存在命令总是适用于本地文件系统。如果你想检查一个远程系统是否有一个文件,你必须 exp_send 它的一些说明来做检查。不幸的是,我不能完全告诉你在说什么,所以我不能真正的建议如何去做。



而且你想要一个 break 之后放置文件复制行,否则它将再次绕过循环。你可能不希望这样做!


I'm trying to check if a file exists or not in Tcl, but I can't seem to get a true result. Even though I know it is present.

while {true} {

    if { [file exists $file_name] == 1} {               
        exp_send "copy file.txt destination \r"
        puts " File copied!"
    }

    puts "File Not copied"

    }

I always execute the File not copied line. I did a put for [file exists $file_name] and I always end up with 0. But I know for a fact that the file exists in the current directory. Any suggestions?

EDIT:

An alternative method that I'm trying to pursue, is that when I do a dir using the tcl script. I will get an output of all the files in the directory. I just need to match my file with the list outputted and satisfy the if when a match was found ...

I'm executing the script from Location A, but using the script to telnet to Location B. When I do a file exists, it checks Location A itself. This is my problem ... since I need to be searching in Location B ...

解决方案

The file exists command always works with local filesystems. If you want to check whether a remote system has a file, you'll have to exp_send it some instructions to do the check for you. Unfortunately, I can't quite tell what you're talking to from your description, so I can't actually advise how to do it.

And you want a break after that puts "File copied" line otherwise it will all go round the loop again. You probably don't want that!

这篇关于Tcl +检查文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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