bat脚本在C:\Program Files (x86)使用管理员权限运行获取当前路径不对。
bat脚本如下:
@echo off set "current_dir=%cd%" echo Current directory: %current_dir% set "filepath=%current_dir%\1.txt" setlocal enabledelayedexpansion if exist "%filepath%" ( for /f "usebackq delims=" %%a in ("%filepath%") do ( echo %%a ) ) else ( echo File not found. ) endlocal pause
普通权限运行bat脚本:
管理员权限运行bat脚本:
所以需要在获取路径之前通过cd /d
命令将工作目录切换到C:\Program Files (x86)
@echo off cd /d "C:\Program Files (x86)" set "current_dir=%cd%" echo Current directory: %current_dir%标签:Files,bat,echo,current,Program,权限 From: https://www.cnblogs.com/log9527blog/p/17446221.html