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 exists() function is a part of the File class in Java. This function determines whether the is a file or directory denoted by the abstract filename exists or not. The function returns true if the abstract file path exists or else returns false.
We can check if a file exists in Ruby by using the exists?() method of the File class. This method returns a Boolean value signifying if the file exists or not.
Tcl, an abbreviation of the name "Tool Command Language", is a scripting language for controlling and extending software applications. A . tcl file contains a Tcl script, which is composed of Tcl functions and can also include Quartus® Prime Application Programming Interface (API) functions used as commands.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With