Windows Command Prompt, how to move folder? - windows

I have a question regarding windows command prompt. I tried to create a cmd file containing simple commands for the use of creating a folder named after the current date , have it create some files and finaly move the folder to a diffrent location. For some reasons the last part is not working right. Here is my code
cd Desktop
mkdir "%DATE%"
cd "%DATE%"
echo new > index.html
echo new > main.js
echo new > style.css
//move "%DATE%" MeineProjekte <---- thats the problem. Hope someone could help me on this.
And if you have any better ways of displaying this code I would appreciate this aswell
I tried to google for a solution and had not mutch luck.

After using CD command, you changed the directory. If your MeineProjekte folder is not located inside the %DATE% folder, you can not move %DATE% there.
I assume that you should use cd .. after echo commands. Something like this:
cd Desktop
mkdir "%DATE%"
cd "%DATE%"
echo new > index.html
echo new > main.js
echo new > style.css
cd ..
move "%DATE%" MeineProjekte
It will work only if MeineProjekte is in the scope. If not, you should specify the absolute path to this folder (e.g. C:\MeineProjekte if it is on your C disk).

I believe your computer does not know if you're talking about a destination file or directory.
You might try the following:
move "%DATE%"\ MeineProjekte
(The backslash says clearly that %DATE% is a directory.)

Related

How to move up multiple folder

Using VS Code terminal, a certain directory keeps popping up as default :
C:\Users\user\name\folder1\folder2\folder3\folder4
How do move back up with one single command instead of doing multiple "cd ../.."
Much appreciated!
Sorry I am answering for CMD as it was tagged CMD, I'm not sure how this affects VSCode. So, I'm not sure if I should just delete this or if it is actually relevant. Please let me know.
What folder do you want to go to?
Using your Example C:\Users\user\name\folder1\folder2\folder3\folder4
If you would like to go to the root CD \ will do.
If you would like to go up 4 directories CD ..\..\..\.. will do
If you want to go up 4 directories and back down 3 CD ..\..\..\..\folder1\folder2\folder3
If you want to always go to a specific directory on the current disk CD \Path\to\directory
If you want to always go to a specific folder on another disk CD /D DriveLetter:\Path\To\Folder (eg CD /D X:\Path\To\Folder)
In VScode, add the exact folder in Workspace, you want to open terminal from.

Change directory in bash script in windows

How can I change my working directory in bash script in windows. I have
~dp0 = C:\test\docker\windows and I want to change my directory to C:\test\build
So it means 2 levels up and then int o build folder
Thanks
Since C:\ is mounted by default into /mnt/c this will work.
Create a .bashrc in your home path by following command:
echo "BUILDDIR=/mnt/c/test/build" >> ~/.bashrc;source ~/.bashrc
cd $BUILDDIR
# Do your work below for example ./configure.
./configure
On my system in Git bash the C:\ root is just /c/ and other dirs from there are whatever they are, so it would be cd /c/test/build/.
You could also still say cd ../../build/.
Good luck.
To change the directory using a bash script is just like you would using normal bash.
cd "C:/test/build"
echo "You're now in the folder, do what you will."
Save the file as .sh and it can be used as such.
Note, when navigation your folders using a bash script remember the directory you'll be starting from is always the home directory.

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.

Create symlink to other paths from babun home directory

I just installed babun on my Windows 7.
babun's ~/home/xxx is located at C:\Users\Admin\.babun\cygwin\home\xxx on windows file system.
xxx is my user name on windows
Let's say my worked files are stored in D:\work, how can I create symlink to link to D:\work?, so I can easily use cd mysymlink to change the working directory from babun's home directory.
Please help.
Thanks.
Try to create a link in / like this:
ln -s /cygdrive/d/work /myworkdir
Then you should be able to cd /myworkdir to your disired directory.
Another option would be to create an alias in your .bashrc:
echo "alias gtw=\"cd /cygdrive/d/work\"" >> ~/.bashrc
After that you could simply write gtw.
Note: gtw means go to work :) but you can choose whatever you like...
Edit: Oh, sorry you added the zsh tag, I didnt see then the second option must be like this:
echo "alias gtw=\"cd /cygdrive/d/work\"" >> ~/.zshrc

.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