@echo off
set /p filename=please enter name of file..:
echo "%filename%"
(
echo %filename%
if exist { C:\Windows\System32\%filename% }
(
wmic datafile where name="C:\\Windows\\System32\\%filename%" get version
wmic datafile where name="C:\\Windows\\System32\\%filename%" get path
)
else
(
wmic datafile where name="C:\\Windows\\System32\\drivers\\%filename%" get version
wmic datafile where name="C:\\Windows\\System32\\drivers\\%filename%" get path
)
) >output.txt
start notepad.exe output.txt
我已将此批处理文件设置为搜索文件,命名文件,获取文件版本并在文本文件中打印现有文件的路径。但是如果else块无法正常工作。请帮助我,并提前感谢。 : - )
答案 0 :(得分:3)
A)Set /p
有引号允许长文件名,这是一种很好的做法
B)if exist
行有相同的原因引用,加上括号在行的末尾
C)) else (
必须在一行
@echo off
set /p "filename=please enter name of file..: "
echo "%filename%"
(
echo %filename%
if exist "C:\Windows\System32\%filename%" (
echo block 1
wmic datafile where name="C:\\Windows\\System32\\%filename%" get version
wmic datafile where name="C:\\Windows\\System32\\%filename%" get path
) else (
echo block 2
wmic datafile where name="C:\\Windows\\System32\\drivers\\%filename%" get version
wmic datafile where name="C:\\Windows\\System32\\drivers\\%filename%" get path
)
) >output.txt
start notepad.exe output.txt