Tcl +检查文件是否存在 [英] Tcl + Check file existence

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

问题描述

我正在尝试检查Tcl中是否存在文件,但似乎无法得到真实的结果.即使我知道它存在.

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"

    }

我总是执行文件未复制"行.我为[file exists $file_name]进行了一次put操作,但我总是以0结尾.但是我知道该文件存在于当前目录中.有什么建议吗?

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?

我正在尝试的另一种方法是,当我使用tcl脚本执行dir时.我将获得目录中所有文件的输出.我只需要将我的文件与输出的列表进行匹配,并在找到匹配项时满足if ...

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 ...

我正在从位置A执行脚本,但是使用该脚本远程登录到位置B.当我执行文件操作时,它会检查位置A本身.这是我的问题...因为我需要在位置B中进行搜索...

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 ...

推荐答案

file exists命令始终适用于本地文件系统.如果要检查远程系统是否有文件,则必须exp_send一些说明来为您进行检查.不幸的是,我不能完全根据您的描述来告诉您您在说什么,因此我实际上无法建议您如何做.

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.

并且您想要在该puts "File copied"行之后的break,否则它将再次循环.您可能不想要那个!

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天全站免登陆