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.

Help with cd command

Old posts that have not been replied to for several years.
Locked
p
prizm

Post by prizm »

I am just learning TCL and am trying to modify this script. Everything works, except that it won't let me cd into a directory that contains charecters like periods and hyphens. I'm having a hard time figuring out what this is doing, but I think its trying to expand the current direcotry to *.* and then compare the cd arguments before changing to the new directory. Is this correct? Could this be where it is choking when the directory contains a period?

#Prog FLASH cd command
if {$args == "cd.."} {
set args "cd";
set filematch "..";
};
if [string match $args "cd" ] {
set chdir $filematch;
if {$chdir == ".."} {
set newdir [string range $activedir 0 [expr [string last "/" $activedir]-1]];
if {[string last "/" $activedir]<0} { set newdir "." };
set wholist [lreplace $wholist $infoseek [expr $infoseek+1] $ip $newdir]; set command 1
};#if
if {$chdir == "/"} {set wholist [lreplace $wholist $infoseek [expr $infoseek+1] $ip "."]; set command 1
};#if
if {$command!=1 && ![string match "*.*" $chdir]} {
if {$chdir != ".."} {
set chdir [string trimright $chdir "/"];
if {[string match $activedir "."] && [file isdirectory "$basedir/$chdir"]} {
set wholist [lreplace $wholist $infoseek [expr $infoseek+1] $ip $chdir] ; set command 1
};#if
if {![string match $activedir "."] && [file isdirectory "$basedir/$activedir/$chdir"]} {
set chdir [string trimright $chdir "/"];
set wholist [lreplace $wholist $infoseek [expr $infoseek+1] $ip "$activedir/$chdir"]; set command 1
};#if
};#if
};#if
if {$command==1} { ircii /msg =$name "^C15^B[^B^C12 [lindex $wholist [expr $infoseek+1]] ^B^C15]" };
if {$command!=1} {
ircii /msg =$name "No such directory!"
set command 1
};#if
};#prog if cd

<font size=-1>[ This Message was edited by: prizm on 2002-06-04 14:45 ]</font>
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

It's awfully hard to read, especially with no formatting (try using the code directive), but the part that is messing up is where it matches against "*.*". It's not trying to expand the dir name, it's just seeing if there are any periods in it. It doesn't really make sense. The logic seems to be that if there is a period, the person must have typed a filename on accident (like cd pics/sheep.jpg or something), so it strips off everything after the last /. You might be able to 'fix' it by adding a / to the end of your cd command, e.g. "cd some.dir/"

I'd find a new script, because that one isn't "good" heh.
p
prizm

Post by prizm »

Sweet, now i see what that does. Though putting a / at the end of the directory still ended in a "No Such Such File or Directory". However, taking out && ![string match "*.*" $chdir] of the code worked :smile: I still dont know why how that affected directories with a hyphen as well..

I understand its a poorly written script, but its the only working fserev script for b/x that I could find. I'll probably just keep modifying it until the script is completely rewritten.

<font size=-1>[ This Message was edited by: prizm on 2002-06-05 17:04 ]</font>
Locked