Tag Archives: file

file and directory selector with gui for tcl – tk

Quick Code: Here is a sample file and directory selector procedure written in tcl – tk. The code is added in my public git repo at git://github.com/rvguiman/tcl-tk.git or https://github.com/rvguiman/tcl-tk.git. Or check the code below.

#-------------------------- gFileDirSelector ------------------------------------------------#
# what: procedure for selecting a file or directory, run it using wish/tk
# arg: optional arg type, valid values none/anything for file selection or "dir" if you want to choose directory instead of file
# return: if type is file, return the full path of file or 0 if cancelled
#--------------------------------------------------------------------------------------------#

proc gFileDirSelector { { type "file" } } {
     if { $type ne "dir" } {
          set types {
          {{text files} {.txt} TEXT}
          {{tcl scripts} {.tcl} }
          {{all files} * }
          }
          set filename [tk_getOpenFile -filetypes $types]
          if {$filename ne ""} {
               puts "file selected -> $filename"
               return $filename
               } else {
               puts "file selection cancelled"
               return 0
               }
          } else {
          set dirSel [tk_chooseDirectory]
          if {$dirSel ne ""} {
              puts "dir selected -> $dirSel"
              return $dirSel
              } else {
              puts "directory selection cancelled"
              return 0
              }
          }
     }


get file date in tcl

Quick Code:
This is a simple tcl script procedure to get the date of a file. The return value is a list containing time in seconds and human readable time in string.

Usage:¬†getFileDate “/docs/sample/test.txt”
Git: git clone https://github.com/rvguiman/tcl.git (added in g_file_utility.tcl)
Or check the code below

proc gGetFileDate { filePass } {
    set secTime [file mtime $filePass]
    set humanTime [clock format $secTime -format "%d_%b_%y_%H:%M:%S"]
    return [list $secTime $humanTime]
    }