How do I find the current directory of a batch file, and then use it for the path?

There is no need to know where the files are, because when you launch a bat file the working directory is the directory where it was launched (the “master folder”), so if you have this structure: .\mydocuments\folder\mybat.bat .\mydocuments\folder\subfolder\file.txt And the user starts the “mybat.bat”, the working directory is “.\mydocuments\folder”, so you only need to write … Read more

How to cd into a directory with space in the name?

$ cd “$DOCS” You need to quote “$DOCS” to prevent spaces from being parsed as word separators. More often than not, variable references should be quoted. Note that $HOME would have the same problem. The issue is coming from when the shell evaluates variable references; it’s nothing to do with what variables you use or … Read more

system(“cd “) in a C program

The changed directory only lasts for the duration of the system command. The command starts a separate program, which inherits its current directory from your program, but when that program exits its current directory dies with it. You can use && to join the commands together, and it will work: system(“cd /D C:\\Users\\USER\\Desktop && mkdir … Read more

Run cmd commands through Java

One way to run a process from a different directory to the working directory of your Java program is to change directory and then run the process in the same command line. You can do this by getting cmd.exe to run a command line such as cd some_directory && some_program. The following example changes to … Read more