Change to new directory (No Answer)

Linux specific forum
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Change to new directory (No Answer)

Post 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?
Last edited by SkyManager on Wed May 23, 2007 3:32 am, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post 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?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Is it possible for me to create a C program and link to purebasic to do the job :roll:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

We don't know what you want...
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post 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.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Have you tried running GetCurrentDirectory() to see if the currentdir has actually been changed during the program?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

It won't change the directory for the parent console. This is not possible.
quidquid Latine dictum sit altum videtur
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

This function SetCurrentDirectory() works in MsWindow
But not in Linux
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post 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 *"
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

By the way, rm * is pretty cool if you have a file called -rf in the directory.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

I'll better test that in a virtual machine ^^
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post 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.
Post Reply