我正在使用Windows XP。想要创建一个批处理文件,它可以在任何位置响应用户输入。除了毛刺之外它工作正常。如果用户输入
C:\Documents and Settings\username\desktop\file.txt
以下批次工作正常:
set /p X= your file ?
set /p =Number: <nul
Find /v /c "" <%1 %X%> linecount.txt msg %username%<linecount.txt || start linecount.txt
del linecount.txt.
但是,如果我们假设用户是计算机saavy并且他将使用此路径
%userprofile%\desktop\file.txt
有或没有引号,批处理文件失败,系统无法找到路径!我在我的智慧结束。
答案 0 :(得分:3)
我可能错了,但我认为%必须在%userprofile之后。
在你的情况下,它将是:
<强>%USERPROFILE%\桌面\ file.txt的强>
答案 1 :(得分:1)
使用此:
set /p X= your file ?
set /p =Number: <nul
call set "X=%X%"
Find /v /c "" <%1 "%X%"> linecount.txt msg %username%<linecount.txt || start linecount.txt
del linecount.txt.
当然,名称必须以正确的方式给出:
%userprofile%\desktop\file.txt
编辑: Windows XP中的输出示例已添加
C:\> ver
Microsoft Windows XP [Version 5.1.2600]
C:\> type test.bat
@echo off
setlocal
set /p X= your file ?
echo Before call set: "%X%"
call set "X=%X%"
echo After call set: "%X%"
C:\> test.bat
your file ? %userprofile%\desktop\file.txt
Before call set: "%userprofile%\desktop\file.txt"
After call set: "C:\Documents and Settings\Antonio\desktop\file.txt"
C:\>
答案 2 :(得分:0)
EUREKA!看起来问题已经解决了。代码如下:
set /p X= your file ?
for /f "tokens=* " %%Y in (' echo %X% ') do set file=%%Y
find /v /c "" < %file% >lines.txt
for /f "tokens=*" %%Z in (lines.txt) Do set number=%%Z
echo Totally %number% lines >nol.txt
del lines.txt
msg %username% < nol.txt || start "" nol.txt
del nol.txt