修改代码将读取文件改成读取当前文件目录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 12:08:22 浏览: 158
这是将代码修改为读取当前文件目录的版本:
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
相关问题
优化这个代码将目录改成读取当前文件下目录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
这是优化后的代码,可以读取当前文件夹下的目录,并使用相对路径:
setlocal enabledelayedexpansion
set file="%~dp0\1.txt"
echo.
set replaced=1234
echo 1234>"%~dp0\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!>>"%~dp0\2.txt"
)
COPY "%~dp0\2.txt" LPT1
goto :1
修改代码将读取文件改成读取当前文件目录并且将条码改成二维码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
这是将代码修改为读取当前文件目录并且将条码改成二维码的版本:
setlocal enabledelayedexpansion
set "file=%~dp0\1.txt"
echo.
set "replaced=1234"
echo QRCode>"%~dp0\2.txt"
echo.
set /p "all=請輸入條碼: "
for /f "usebackq delims=" %%i in ("%file%") do (
set "str=%%i"
set "str=!str:%replaced%={{QRCode:!all!}}!"
echo !str!>>"%~dp0\2.txt"
)
COPY "%~dp0\2.txt" LPT1
goto :1
阅读全文