-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPsiUtilString.tcl
31 lines (27 loc) · 955 Bytes
/
PsiUtilString.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
##############################################################################
# Copyright (c) 2019 by Paul Scherrer Institute, Switzerland
# All rights reserved.
# Authors: Oliver Bruendler
##############################################################################
namespace eval psi::util::string {
#Copy a file and replace one or mor tags within a template file
#
# @param fromPath Source path of the file (template)
# @param toPath Destination path to write the modified file to
# @param tags A dictonary containing tags as keys and their replacements as values
proc copyAndReplaceTags {fromPath toPath tags} {
#read file
set fp [open $fromPath r]
set content [read $fp]
close $fp
#replace tags
foreach item [dict keys $tags] {
set val [dict get $tags $item]
set content [regsub -all $item $content $val]
}
#write file
set fp [open $toPath "w+"]
puts -nonewline $fp $content
close $fp
}
}