修改代码将读取文件改成读取当前文件目录setlocal enabledelayedexpansion set file="E:\labelprint\1.txt" echo. set replaced=1234 echo 1234>"E:\labelprint\2.txt" echo. set all= set /p all=請輸入條碼: for /f "delims=" %%i in ('type "%file%"') do ( set str=%%i set "str=!str:%replaced%=%all%!" echo !str!>>"E:\labelprint\2.txt" ) COPY "E:\labelprint\2.txt" LPT1 goto :1
时间: 2023-10-16 19:08:22 浏览: 154
CHGFName.rar_修改文件名_批量_批量修改文件名_文件批量修改名称
这是将代码修改为读取当前文件目录的版本:
setlocal enabledelayedexpansion
set "file=%~dp0\1.txt"
echo.
set "replaced=1234"
echo 1234>"%~dp0\2.txt"
echo.
set "all="
set /p "all=請輸入條碼: "
for /f "usebackq delims=" %%i in ("%file%") do (
set "str=%%i"
set "str=!str:%replaced%=%all%!"
echo !str!>>"%~dp0\2.txt"
)
COPY "%~dp0\2.txt" LPT1
goto :1
阅读全文