Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file join* will skip "$TMP" if
*absolute* path is found.
- the GOAL is to create a new path with *prefix* "$TMP" using the local path separator
set tmpFile [file concat $TMP [ file normalize $F ]]
will solve this issue.
example:
TMP = /tmp
file normalize $F = /a/b
OLD: file join /tmp /a/b -> /a/b
NEW: file concat /tmp /a/b -> /tmp/a/b
mfg AO
Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file join*
will skip "$TMP" if
*absolute* path is found.
→ the GOAL is to create a new path with *prefix* "$TMP" using the local path separator
set tmpFile [file concat $TMP [ file normalize $F ]]
will solve this issue.
example:
TMP = /tmp
file normalize $F = /a/b
OLD: file join /tmp /a/b → /a/b
NEW: file concat /tmp /a/b → /tmp/a/b
mfg AO
Am 12.05.24 um 11:58 schrieb aotto1968:
Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file
join* will skip "$TMP" if
*absolute* path is found.
→ the GOAL is to create a new path with *prefix* "$TMP" using the
local path separator
set tmpFile [file concat $TMP [ file normalize $F ]]
will solve this issue.
example:
TMP = /tmp
file normalize $F = /a/b
OLD: file join /tmp /a/b → /a/b
NEW: file concat /tmp /a/b → /tmp/a/b
mfg AO
# Idea
#https://wiki.tcl-lang.org/page/namespace+ensemble
#proc ::tcl::dict::get?
package require fileutil
proc ::tcl::file::concat {args} {
if {[llength $args] != 2} {
return -code error "This function expects exactly two arguments"
}
try {
file normalize [file join [lindex $args 0] [fileutil::stripPath [lindex [file split [lindex $args 1 ]] 0] [lindex $args 1]]]
}
}
namespace ensemble configure file -map \
[dict merge [namespace ensemble configure file -map] {concat ::tcl::file::concat}]
#Example
puts [file concat /tmp [pwd]]
#This Tcl script defines a procedure
#::tcl::file::concat that concatenates two file paths and normalizes the result.
mfg
Gregor
Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file
join* will skip "$TMP" if *absolute* path is found.
→ the GOAL is to create a new path with *prefix* "$TMP" using the local path separator
Am 12.05.24 um 14:21 schrieb greg:
Am 12.05.24 um 11:58 schrieb aotto1968:
Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file
join* will skip "$TMP" if
*absolute* path is found.
→ the GOAL is to create a new path with *prefix* "$TMP" using the
local path separator
set tmpFile [file concat $TMP [ file normalize $F ]]
will solve this issue.
example:
TMP = /tmp
file normalize $F = /a/b
OLD: file join /tmp /a/b → /a/b
NEW: file concat /tmp /a/b → /tmp/a/b
mfg AO
# Idea
#https://wiki.tcl-lang.org/page/namespace+ensemble
#proc ::tcl::dict::get?
package require fileutil
proc ::tcl::file::concat {args} {
if {[llength $args] != 2} {
return -code error "This function expects exactly two arguments"
}
try {
file normalize [file join [lindex $args 0] [fileutil::stripPath
[lindex [file split [lindex $args 1 ]] 0] [lindex $args 1]]]
}
}
namespace ensemble configure file -map \
[dict merge [namespace ensemble configure file -map] {concat
::tcl::file::concat}]
#Example
puts [file concat /tmp [pwd]]
#This Tcl script defines a procedure
#::tcl::file::concat that concatenates two file paths and normalizes
the result.
mfg
Gregor
Works for me here on Linux and Windows.
- check if two arguments
- applies file split to argument 2 to find "root"
- applies fileutil:stripPath along with the "root" and removes the
"root" from argument 2
-applies file join to argument 1 and argument 2
-applies file normalize
Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file join*
will skip "$TMP" if
*absolute* path is found.
→ the GOAL is to create a new path with *prefix* "$TMP" using the local path separator
set tmpFile [file concat $TMP [ file normalize $F ]]
will solve this issue.
example:
TMP = /tmp
file normalize $F = /a/b
OLD: file join /tmp /a/b → /a/b
NEW: file concat /tmp /a/b → /tmp/a/b
mfg AO
At Sun, 12 May 2024 11:58:19 +0200 aotto1968 <[email protected]> wrote:
Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file join* will skip "$TMP" if
*absolute* path is found.
- the GOAL is to create a new path with *prefix* "$TMP" using the local path separator
Why would you really want to do that? Please explain your use case...
set tmpFile [file concat $TMP [ file normalize $F ]]
will solve this issue.
example:
TMP =tmp
file normalize $F =a/b
OLD: file join /tmp /a/b -> /a/b
NEW: file concat /tmp /a/b -> /tmp/a/b
Your solution *will fail* under MS-Windows (and maybe MacOSX). I *think* file
normalize under MS-Windows might include the drive letter and may swap '/'s with '\'s. Under MacOSX might result in a path starting with MacOSX root paths. Note: under Linux (and UNIX) this also happens. This means that you final result is not going to be a valid existing pathname on any system, although under UNIX-ish systems it might make some kind of sense, if one is playing with virtual file systems or something.
mfg AO
One reason to introduce the *file concat* is that windows etc add a lot of extra chars.
I'm on unix *without* drive-letter etc
some restrictions:
1) the windows-file-letter should be skipped *or* be first part of the path
file concat c:\tmp d:\a\b â c:\tmp\a\b ⦠or ⦠c:\tmp\_d_\a\b
the *goal* of this is to make a kind of "backup" from an exiting file with path into a *tmp* directory
*and* keep the directory-tree valid
I think "wget" is doing something like this to copy a html-tree on to disc
On 12.05.24 14:37, Robert Heller wrote:
At Sun, 12 May 2024 11:58:19 +0200 aotto1968 <[email protected]> wrote:
Hi,
the following code does *not* work :
set tmpFile [file join $TMP [ file normalize $F ]]
because *file normalize* will return an *absolute* path and *file join* will skip "$TMP" if
*absolute* path is found.
- the GOAL is to create a new path with *prefix* "$TMP" using the local path separator
Why would you really want to do that? Please explain your use case...
set tmpFile [file concat $TMP [ file normalize $F ]]
will solve this issue.
example:
TMP =tmp
file normalize $F =a/b
OLD: file join /tmp /a/b -> /a/b
NEW: file concat /tmp /a/b -> /tmp/a/b
Your solution *will fail* under MS-Windows (and maybe MacOSX). I *think* file
normalize under MS-Windows might include the drive letter and may swap '/'s with '\'s. Under MacOSX might result in a path starting with MacOSX root paths. Note: under Linux (and UNIX) this also happens. This means that you final result is not going to be a valid existing pathname on any system, although under UNIX-ish systems it might make some kind of sense, if one is playing with virtual file systems or something.
mfg AO
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 147:25:38 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,532 |