Get and Set current working directory

I am trying to run a command using shell.
I need to get the current working directory, save it, then set it to a new directory, run my command and then switch back to the saved directory.
What commands are there to get and set the current working directory?

Which platform?

You have 2 options: Use the shell in Interactive move (mode = 2) or write a script file and execute it in the shell.

There is another option: Prefix your command with "cd /path/to/wd/ ; " (Mac, Linux). So let’s say you wanted a list of files, the command would look like this:

dim cmd as string = "cd " + f.ShellPath + " ; "
cmd = cmd + "ls -a"
sh.Execute cmd

There is no need to change it back.

What about SpecialFolder.CurrentWorkingDirectory


If you’re using a shell then @Kem Tekinay’s suggestion should work. [quote=34649:@Brian O’Brien]SpecialFolder.CurrentWorkingDirectory[/quote]
I’m embarrassed that I never noticed that. Is it new? That’s probably what you want.

It’s read only. :frowning:
This is rather disturbing…

Regardless, I don’t think that solves the problem for the shell. The first rule of shell programming is: Make no assumptions about the environment. Be explicit with paths.

I have Windows-specific code to get/set the CWD, but using the shell ought to work on all platforms.

System.EnvironmentVariable works if you call it before shelling out.
and the environment variable is accessible by the shell …
(Not that I want to change the subject but I can set an environment variable in my application prior to shelling out and that enviroment variable is in fact set when the shell exectutes.)

This it the first ‘basic’ language that I’ve worked on that doesn’t have pwd and chdir built in.

Most basic languages are console-oriented, where the concept of “working directory” makes sense.

It seems to me that the concept of a default working directory for the OS that an application runs on is not a function of the user interface. Indeed Micro$oft Basic has the notion with commands like pwd and chdir and xojo had the notion of System.CurrentWorkingDirectory. but …