Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

chdir/setcurrentdir

38 views
Skip to first unread message

Tod Jackson

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
I have a console app that I'm wanting to use as a "directory navigation"
utility from the command line. It stores aliases and their path in the
registry and then when I pass the alias to the app, it will take me to the
directory associated with the alias.

I'm trying to use the chdir() and/or setcurrentdir() functions but they
aren't reflecting the change in the console (dos prompt). The application
thinks it's changed directories but it's not physically reflected in the
window.

Is there something else that might provide this? Am I missing something? I
thought this seemed fairly straight forward but it's not behaving like I
thought it should.

Any suggestions are appreciated.

Thanks,
Tod Jackson
jack...@uillinois.edu

Philippe Ranger

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
<<Tod:

I'm trying to use the chdir() and/or setcurrentdir() functions but they
aren't reflecting the change in the console (dos prompt).
>>

This is where you learn that Win32 isn't Dos-based. Each Win32 app runs in a
separate process, with its separate dir settings, among other things. When
you launch a console app from a console, you are launching a new process,
from an existing one, both happening to use a console user interface. You
can easily show that your chDir or setCurrentDir *are* successful, within
your console app. They just have no effect at all on the calling process.

Dos apps, by contrast, all ran *and still run* in the same process, the
console process they're launched from. I have BP7, and my workaround for
your problem is to do this in BP7 -- where it works perfectly. However, I
have no idea how to do it from a console app, and my current opinion is that
its not possible -- you can't get another process's directory changed
without that process's collaboration.

There might be a trick to feed the directory string back to a batch file
from which your app would be called, but I don't know how to do it.

PhR

Tod Jackson

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
Your explanation makes sense to me. Thanks. I'll do it in BP7 if i can't
figure out a way get it done with Delphi. Maybe i can somehow get a handle
to the process inwhich my console app starts in and apply the changes to
that process instead of the new one that gets fired off.

Thanks again.
TJ

Philippe Ranger <.> wrote in message news:7hv3n3$et...@forums.borland.com...

Peter Below (TeamB)

unread,
May 20, 1999, 3:00:00 AM5/20/99
to
> I have a console app that I'm wanting to use as a "directory navigation"
> utility from the command line. It stores aliases and their path in the
> registry and then when I pass the alias to the app, it will take me to the
> directory associated with the alias.
>
> I'm trying to use the chdir() and/or setcurrentdir() functions but they
> aren't reflecting the change in the console (dos prompt). The application
> thinks it's changed directories but it's not physically reflected in the
> window.
>
> Is there something else that might provide this? Am I missing something? I
> thought this seemed fairly straight forward but it's not behaving like I
> thought it should.

It will not work, Tod. In Win32 the "current directory" is a purely
process-local concept. A process cannot change the current directory for its
parent process, only for child processes it spawns (via ShellExecute or
CreateProcess).

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


Kent Briggs

unread,
May 20, 1999, 3:00:00 AM5/20/99
to
Philippe Ranger wrote:

> <<Tod:


> I'm trying to use the chdir() and/or setcurrentdir() functions but they
> aren't reflecting the change in the console (dos prompt).
> >>

> There might be a trick to feed the directory string back to a batch file


> from which your app would be called, but I don't know how to do it.
>
> PhR

Using a batch file is how I got my Directory Maven 95 program
(http://www.briggsoft.com/dm95.htm) to change directories with a console app.

--
Kent Briggs, kbr...@briggsoft.com
Briggs Softworks, http://www.briggsoft.com

0 new messages