Here’s a script I wrote to do something similar in a tps proc. This script takes a list of files passed by tpsScanDir. You can modify it or use some of the lines to do what you need.
#
# Purpose: Rename the files picked up and passed by tpsScanDir.tcl
# and sent to tpsPgpSend. This script was created originally to
# remove underscores in file names being sent to PGP for
# encryption. The underscores are not allowed by PGP.
# Author: Max Drown
# Date: 05/02/2006
# Args: tps keyedlist containing:
# MODE run mode (”start” or “run”)
# MSGID message handle
# Returns: list containing new file names
#
proc tpsRenameFiles { args } {
global ibdir HciProcess
keylget args MODE mode
switch -exact — $mode {
start {
echo “[whereAmI] Shutdown mode'”
}
run {
keylget args MSGID mh
set fileList [msgget $mh]
set dispList “{CONTINUE $mh}”
set newFileList {}
puts “[whereAmI] Begin.”
foreach inFile $fileList {
if {[regexp {tpsPgpSend} $inFile] == 0} {
# Convert underscores to dashes
puts “[whereAmI] Converting underscores to dashes in $inFile”
regsub -all {_} $inFile {-} newFile
#regsub {.} $newFile {-} newFile
# Create a new list of files with the new file names
lappend newFileList $newFile
# Rename and move the file
if {[catch {exec mv $ibdir/$inFile $ibdir/$newFile} catch_return]} {
puts “[whereAmI] Error: Moving $inFile to $newFile failed: $catch_return”
puts “[whereAmI] End.”
catch {exec hcienginestop -p $HciProcess > /dev/null &} catch_return
return “”
} else {
puts “[whereAmI] Moved $inFile to $newFile (underscores converted to dashes)”
}
} else {
# The file has already been renamed
lappend newFileList $inFile
}
}
puts “[whereAmI] DEBUG: newFileList= $newFileList”
puts “[whereAmI] DEBUG: dispList= $dispList”
puts “[whereAmI] End.”
msgset $mh “$newFileList”
return $dispList
}
shutdown {
echo “[whereAmI] Shutdown mode'”
}
default {
echo “[whereAmI] Unknown mode: $mode”
return “”
}
}
}
Here’s one way to get a time stamp into a variable.
set messageTs [clock format [clock seconds] -format %Y%m%d%H%M%S]