This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Old posts that have not been replied to for several years.
sirkrunch
Voice
Posts: 19 Joined: Wed Oct 09, 2002 2:36 am
Post
by sirkrunch » Fri Feb 14, 2003 4:18 am
I have this
$string /path/to/a/dir/and/file.txt
i want to split it, have one variable with the full path but no file
and another with just the fille name, how do i go about that??
GodOfSuicide
Master
Posts: 463 Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria
Post
by GodOfSuicide » Fri Feb 14, 2003 4:42 am
i'm not that good in tcl, but i can tell you what logical way you have to go:
cos in the filename ther cant be a "/" character you have to find the position of the last "/" in the string.
Then copy all from first character in the string to the position you just found into a variable. Do the same from the position you found + 1 to the last character. Then you have split it up.
/path/to/a/dir/and/file.txt
______________|
find this one
/path/to/a/dir/and/file.txt
|---------------------|
copy from start till last "/"
/path/to/a/dir/and/file.txt
_______________|------|
copy from last "/" + 1 to end.
now somebody who knows TCL got to write the code, but i hope my theoretical method can help.
(board unformated my " "'s, so i just made "_"'s)
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Fri Feb 14, 2003 4:47 am
set line "/path/to/a/dir/and/file.txt"
set result [string trim $line "file.txt"]
result: /path/to/a/dir/and/
Once the game is over, the king and the pawn go back in the same box.
Papillon
Owner
Posts: 724 Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no
Post
by Papillon » Fri Feb 14, 2003 4:59 am
or:
Code: Select all
set line "/path/to/a/dir/and/file.txt"
set dir [lindex [split $line /] end] #will return "file.txt"
set file [join [lrange [split $line /] 0 end-1] /] #will return "/path/to/a/dir/and"
this will give you both dir and filename, even if you don't know the filename
btw.. love your "graphical" demonstration GodOfSuicide
Elen sila lúmenn' omentielvo
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Fri Feb 14, 2003 5:41 am
Tcl has a lovely set of built in commands, for operating on filenames.
What makes it even better, it works on ALL OS's. Meanign there are nor incompatabilities between scripts.
Code: Select all
set fullfile "/my/file/is/here/and/called/ppslim.doc"
set dirname [file dirname $fullfile]
set filename [file tail $fullfile]
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Fri Feb 14, 2003 6:08 am
Haha, now you have 3 types to choose from
Once the game is over, the king and the pawn go back in the same box.
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Fri Feb 14, 2003 6:18 am
Make it four!
set fullfile "/path/to/file.ext"
regexp {(^.*)/([^/]*$)} $fullfile match dirname filename
ppslim's way is best though
GodOfSuicide
Master
Posts: 463 Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria
Post
by GodOfSuicide » Fri Feb 14, 2003 6:32 am
Papillon wrote:
btw.. love your "graphical" demonstration GodOfSuicide
that was the way i do it in delphi....so i tried to symbolize my way