user1270123
user1270123

Reputation: 573

How to point TCL procedure to a different directory

I have a procedure which accepts files . I have stored these files in the Tcl\bin folder.Now if i have these files in a different folder , probably a shared folder. How can I point to that specific folder to get these files as input parameters to this procedure?

                    proc test {File1 File2 }

Upvotes: 0

Views: 1718

Answers (1)

thelazydeveloper
thelazydeveloper

Reputation: 3878

Whether you're using a relative or absolute file path, you can use the file command and its options to detect certain things like access rights. From there you can get away with just using the open/read/gets/close commands to read them in. e.g.:

#!/usr/bin/tclsh

set path "path/to/file/directory/"
set name "file.name"

if {[file exists $path$name]} {
    if {[catch { set handle [open $path$name] }]} {
        puts "Could not open $path$name"
    } else {
        set data [split [read $handle] "\n"]
        close $handle
    }
}

Upvotes: 2

Related Questions