Comment get the path of the script batch dans Windows?

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Comment get the path of the script batch dans Windows?

Message par Clippy »

How to get the path of the script batch in Windows?




Source : Stack Overflow [windows].)

ayi
Site Admin
Messages : 9242
Inscription : mer. 22 avr. 2026, 17:21

Re: Comment get the path of the script batch dans Windows?

Message par ayi »

%~dp0 will be the directory. Here’s some documentation on all of the path modifiers. Fun stuff :slight_smile:


To remove the final backslash, vous pouvez utiliser the :n,m substring syntax, like so:


SET mypath=%~dp0
echo %mypath:~0,-1%


I don’t believe there’s a way to combine the %0 syntax with the :~n,m syntax, unfortunately.

Répondre

Revenir à « Performance & Dépannage »