.BAT = Change the path of %~dpnx0
micromega
-
micromega -
micromega -
Bonjour,
I use this code
However, I would like to move from this path to use another path.
Example: the ".bat" file is in F:\Mon\Dossier 1\fichier.bat
the command set currentpath=%~dpnx0 gives me this path, but I would like to go to F:\Mon\Dossier 2\Dossier 3\fichier.exe
How can I change directories from there?
Thank you
I use this code
set currentpath=%~dpnx0to get the path of the .bat file.
However, I would like to move from this path to use another path.
Example: the ".bat" file is in F:\Mon\Dossier 1\fichier.bat
the command set currentpath=%~dpnx0 gives me this path, but I would like to go to F:\Mon\Dossier 2\Dossier 3\fichier.exe
How can I change directories from there?
Thank you
4 answers
-
Hello.
currentPath is a variable created by set.
currentPath is a variable assigned by another ms-dos variable
that returns the path and its file.
d represents the drive letter
p represents the file path
n represents the file name
x represents the file extension.
To modify this path, you need to retrieve the path without the file.
~dp0
Once the path is obtained through the ~dp0 variable, you add two dots to go up one folder.
~dp0..\
In the upper folder, you specify the folder in which you want to place yourself, followed by the file name if desired. In my case, an html file.
%~dp0..\mars-radio-dnb-2\index.html
To keep the currentPath variable, I created another variable
called cheminAuxiliare and assigned it the path I wanted.
You just need to put echo in front of this variable to display it, or remove echo to launch the program. Here, in my case, it launches an html page.
@echo off
set currentpath=%~dp0
set cheminAuxiliare=%~dp0..\mars-radio-dnb-2\index.html
%cheminAuxiliare%
pause -
Hello,
I don't remember, it's been a long time
but from this path, you create a file containing the variables of the paths you call with the call command I think (I need to check tonight... if no one has answered you in the meantime).
I don't remember, but if I look through my code, I should find it...
--
I think I'm smart enough to say that I know nothing... -
Hello and thank you for your help!
Indeed, the solution from codeurh24 seems to work. Thank you.
However, you mention "once the path obtained by the variable ~dp0, we add the two dots to move up one folder." >> 2 dots to move up one folder, but if we want to go up 3 or 4 folders for example, does that work or is there another technique? -