ActiveState Code

Recipe 364227: checkFile


Check if file exists. Set return code.

Tcl
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Proc - check if file exists. Set return code.
###############################################
proc checkFile {fileName} {
    
    if {[file exists $fileName] == 1} {
       puts "\nfile exists: $fileName\n"	
       return 0
       } else {
               puts "\nfile does not exist: $fileName\n"	
	       return -code error 1
    }
}

Sign in to comment