Windows batch file starting directory when 'run as admin'

前端 未结 8 1681
情书的邮戳
情书的邮戳 2020-12-12 20:02

I have a batch file which is in a directory and must be run from there as well because it updates files within this directory.
This works perfectly fine, except when t

8条回答
  •  一整个雨季
    2020-12-12 20:40

    You can CD directly from the file name by adding the parent (not tested in windows 8.x, but has worked "forever" as far as I can remember).

    CD %FILENAME%\..
    

    and CD will change drives as well using /D, which is shown above but not explicitly mentioned so might be missed. CD /D %FILENAME%\..

    (FOR /? IF /? SET /? CALL /? GOTO /? all provide highly useful reading if you use cmd.exe, I reread them once in a while.)

提交回复
热议问题