Page 1 of 1

Change to new directory (No Answer)

Posted: Wed May 16, 2007 5:32 am
by SkyManager
I use the following codes to change to a new directory :

Code: Select all

SetCurrentDirectory("/home")
End
I am originally in a directory "/root".
After running the above code, I expect to be in the /home directory.
But the actual result is that I am still in /root directory

Can anybody help me out?

Posted: Wed May 16, 2007 9:00 am
by Trond
If that's the case then it's a bug. But remember that it changes the working directory of your PROGRAM, so if you run it from the shell you won't notice a change in the SHELL's path.

Posted: Wed May 16, 2007 11:57 am
by SkyManager
You mean it only change the working directory inside the program and did not change the actual current directory?
What should I do to change the actual current directory?

Posted: Wed May 16, 2007 12:23 pm
by ts-soft
All processes have it's own current directory. There is no global
currentdirectory. You can set it, for example with RunProgram, by set the
optional WorkingDirectory$ parameter, or by doubleclick in filemanager

Posted: Wed May 16, 2007 11:57 pm
by SkyManager
Is it possible for me to create a C program and link to purebasic to do the job :roll:

Posted: Thu May 17, 2007 10:49 am
by Trond
We don't know what you want...

Posted: Fri May 18, 2007 12:41 am
by SkyManager
I want to change the current directory
For example,
I am in the directory "/root"
Running the PB program to call SetCurrentDirectory will change to a new directory.

Posted: Fri May 18, 2007 1:30 am
by GeoTrail
Have you tried running GetCurrentDirectory() to see if the currentdir has actually been changed during the program?

Posted: Fri May 18, 2007 2:08 am
by freak
It won't change the directory for the parent console. This is not possible.

Posted: Fri May 18, 2007 12:24 pm
by SkyManager
This function SetCurrentDirectory() works in MsWindow
But not in Linux

Posted: Fri May 18, 2007 3:43 pm
by Nik
Yes because Windows<>Linux Linux is a Unix like Operating System which is built for multi user use. So there can't be a global directory path as in the DOS like commandline environment of Windows which is only built for one user at a time. Just imagine one user would change his current directory and all other users would suddendly be in another directory which might to data loss if for example those users run "rm *"

Posted: Fri May 18, 2007 4:13 pm
by Trond
By the way, rm * is pretty cool if you have a file called -rf in the directory.

Posted: Fri May 18, 2007 5:31 pm
by Nik
I'll better test that in a virtual machine ^^

Posted: Fri May 18, 2007 5:43 pm
by Nik
Well actually it's no problem when using a really smart shell like zsh, zsh asks wether I really want to delete the whole root dir^^ lets try bash, well bash just ignores the file "-rf" so in both of them it atleast becomes kind of undeleteable
unless you use "./-rf" ok, even /bin/sh does ignore the file, seems to be pritty save to have files like that lying around, but keep in mind not to use RunProgram with rm in that way without checking.