CD command is not working - windows

I am unable to change directory to a path stored as a variable value.
cd %VBOX_INSTALL_PATH%
If I input the command at the cmd.exe prompt it's working, but the same is not working in a batch file.
It's printed as:
cd C:Oracle/vbox
C:Oracle/vbox Not a valid directory path
Kindly help me to resolve it.

The CD command looks like this: CD C:\Oracle\vbox So if the error message is cd C:Oracle/vbox;C:Oracle/vbox Not a valid directory path Kindly help me to resolve it. I assume the content of %VBOX_INSTALL_PATH% is not C:\Oracle\vbox but something else. There is at least a \ missing right after C:. Further, this will only work as you expect if you are already on drive C:. If you want the command to work from everywhere, you should add the /D parameter:
SET "VBOX_INSTALL_PATH"="C:\Oracle\vbox"
CD /D %VBOX_INSTALL_PATH%
And by the way, / is the regular path separator for LINUX. For Windows, it is \. Windows will often accept / but in some cases, it might cause trouble.

Related

Cannot change directory in psql on windows 10. PostgreSQL 11

I downloaded local PosgreSQL 11 on Windows 10.
I try to change directory in psql on command line window to c:\Program Files\PostgreSQL\11\bin>
I get either invalid command or directory does not exist
I tried following with
postgres=# cd c:\Program Files\PostgreSQL\11\bin
Invalid command \Program. Try \? for help.
postgres-# \cd c:\Program Files\PostgreSQL\11\bin
Invalid command \Program. Try \? for help.
postgres-# \cd..
Invalid command \cd... Try \? for help.
postgres-# \cd ..
postgres-# \cd Program Files
\cd: could not change directory to "Program": No such file or directory
I'm not even sure about current directory as pwd is not recognized:
postgres-# \! pwd
'pwd' is not recognized as an internal or external command,
operable program or batch file.
many thanks in advance
UPADATE: Figured out how to check current directory \! cd
Tried to run command this way \! C:\>cd C:\Program Files\PostgreSQL\11\bin
I get:
postgres-# \! C:\>cd C:\Program Files\PostgreSQL\11\bin
Access is denied.
A bit late for OP, but here are some tips for others who stumble in here.
There are two relevant psql commands for these directory change and drive change tasks.
The "built-in" \cd command. You can use this to actually perform the change of directory. However, where Windows uses backslash, use instead forward slash. Also, this command understands drive letter, and unlike Windows cd, you don't have to add a flag to change drive with the cd command here. Examples:
\cd /dir1/dir2
\cd D:/dira/dirb <-- Drive letter
\cd '/dir with spaces/other dir' <-- single quotes
Problem: How do you display the current drive/directory? Unlike in Windows, if you issue a \cd with no argument, psql does not show you the current directory. Instead it changes to the root C:\ directory (presumably in analogy to linux cd command changing to home directory.) So you need to issue a different command to see current directory.
psql can call a shell command, using the form \! <command>
So in linux you could use \! pwd to view present working directory. However, Windows doesn't have a pwd command. But you could use \! cd.
This is apt to get confusing, and prone to accidentally using \cd (which changes the directory unwantedly) when you intended ! cd, especially if you're jumping between Windows and Linux. So on Windows you might want to create a batch file to implement pwd.
As a further point of confusion, you might think to use something like:
\! cd \dira\dirb , however, for some reason, running \! cd with arguments doesn't seem to work (forward or back slashes).
An additional alternative, if you only need to change to a particular current directory once, you could cd before running the script that launches psql. That is to say, don't use the "SQL Shell (psql)" command that Postgresql installs on the Start Menu. Instead, look at the properties of that command, note the path to the script, and use that in a command window only after you've cd'ed to the desired directory.
You could try
postgres=# \cd 'c:\\Program Files\\PostgreSQL\\11\\bin'
I'm using windows btw
You have to change your directory before you run psql
Now, you might be thinking but when I open psql shell Its already running psql that's because you opened it in psql shell, don't do that
Here's what you need to do
open command prompt
change your directory using cd
then run the psql command
if you are getting 'psql is not a command' error, that is because the psql path is not in your environmental variables
if you need to fix that go to this page..→ Click me

Issue with win cmd finding folders

I am having an issue with the windows cmd line. When I cd into my Users dir my user folder shows as there but I cannot cd into. The path cd\Users\gmenfan83\ is my desired location. However, when I am in the Users dir and cd\Users\gmenfan83 \ I get a "The path is not found or specified" . I am more of a nix user but if the folder shows in the directory tree shouldn't I be able to cd into it? Thank you
Are you trying to use cd/Users/gmenfan83 while you have already used cd/Users? In that case you will not be able to find the file since you are already in the Users folder. Typing cd \Users\gmenfan83 right after opening cmd with C drive path should get you there.
It's unclear (even after your edit) what specifically you're doing, but this should get you started.
If you're currently in C:\users, and you want to change into the C:\Users\gmenfan83 folder, all you need is cd gmenfan83. If you're in C:\, all you need is cd users\gmenfan83.
Relative paths also work in Windows cmd.exe just as they do under *nix. To change from C:\users\gmenfan83\test to C:\users\gmenfan83\temp, you can use cd ..\temp, or specify cd \users\gmenfan83\temp.

How to change directory under git bash

Could you tell me please how to change directory using git bash?
Exactly I want go to C:/Program Files
I type cd c:/ - move to c:/.
I type cd Program Files and I get message that "there is no such directory Program".
So the problem is how to go to the directory name of which consists of two words that are separated by whitespaces.
I'm using Windows 7 operating system.
cd gets just one argument, so if you say cd Program Files it does cd Program. So you need to quote Program Files if you want cd to it as just one argument:
cd "Program Files"
otherwise it is trying to find the directory Program.
You could also type the space as escape seqence:
cd /c/Program\ Files/Git/
Please find below to add windows path in git bash or in unix
export PATH=$PATH:/c/Program\ Files/Java/jdk1.8.0_221/bin:/c/Program\ Files/apache-maven-3.6.1/bin

Setting environmental variable in batch as a path (not working for me) on Windows

I want to set my folder C:\Users\scruff\Desktop\MinGW2\Cross as variable PREFIX
So I type:
set PREFIX=C:\Users\scruff\Desktop\MinGW2\Cross
But then when I do:
cd PREFIX
I get
"The system cannot find the specified path".
When I do
echo %PREFIX%
I get:
C:\Users\scruff\Desktop\MinGW2\Cross
when is do:
cd C:\Users\scruff\Desktop\MinGW2\Cross
it takes me to the cross directory fine.
:(
Try cd %prefix%.
DOS/Windows batch files aren't really very clever, you might want to investigate Powershell as an alternative: http://technet.microsoft.com/en-us/scriptcenter/dd742419

.bat file - cd to a directory with a space in its name and also using a variable?

ive written a quick .bat file that reads in the name of a directory typed in by the user, i store that variable in a variable, and then i want to actually cd to that directory.
i've tested it out with simple directories like "C:," for instance, and that works. however, when i'm dealing with the user entering in something like "C:\Documents and Settings\Desktop," i can't do cd %directory%\sampleFolder.
i keep getting an error of "the system cannot find the path specified," even though i'm using the full name. anyone know how to overcome this?
How about:
cd "%directory%\sampleFolder"
set /p DIR="path:"
cd %DIR%
Works just fine.
#ECHO OFF
ECHO Enter Directory
SET/p directory=
CHDIR %directory%
Works for me (Windows 7) but should work for XP/Vista/etc

Resources