我想用批處理實現(xiàn)向s.txt中多次分別導入文本例如:“aaaa","bbbb","cccc","dddd"
實現(xiàn)s.txt內效果如:
aaaabbbbccccdddd
可是echo命令每次導入的時候會強制換行,如:
aaaa
bbbb
cccc
dddd
我該怎么實現(xiàn)我想要的一行效果呢?謝謝!
答案:
echo 做不到,不過可以執(zhí)行以下語句到達到目的
代碼如下:
>>s.txt set /p="aaaa" <nul
>>s.txt set /p="bbbb" <nul
>>s.txt set /p="cccc" <nul
>>s.txt set /p="dddd" <nul
s.txt的內容將是 aaaabbbbccccdddd
注1:“ >>s.txt”這里是輸出流定向的意思,把輸出流重定到了s.txt文件,“<nul ”則是把輸入流指定成了nul,所以set/p="aaaa"就不用等待用戶輸入了。
其實把寫文件操作放到后面更容易讓人理解些:set /p="aaaa"<nul>>s.txt
注2:關于set/p="aaaa"的詳細內容請查看《set命令》
實例1:
if exist %statFile2% ( >>%statFile2% set/p=,%%i<nul ) else ( >>%statFile2% set/p=%%i<nul )
實例2 ----(個人添加)
代碼如下:
@echo off
del b.txt
del c.txt
del d.txt
if exist "%cd%\zhI386" rd /s /q "%cd%\zhI386"
md zhI386
::for /r "%cd%\eni386\" %%i in (*) do (echo %%i>>b.txt)
for /f %%i in ('dir /b %cd%\eni386\') do (
echo %%i>>c.txt
if exist "%cd%\zhall\i386\%%i" (copy "%cd%\zhall\i386\%%i" "%cd%\zhI386\"
) else (>>d.txt set /p="zhall\i386\%%i"<nul&echo ----Not exist>>d.txt)
)
windows批處理之六-echo輸出不換行
完整案例:
Code:
代碼如下:
@echo off
set /p="hello "<nul
set /p="world "<nul
echo again
echo new line
Result:
hello world again
new line
應用:
代碼如下:
echo off
set csvpath=測試數(shù)據(jù)
set sqluldr=D:\sqluldr\sqluldr2sdk\sqluldr2
set sqlpath=導出模板
rem set filename=產品行情
rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log
rem
rem set filename=產品行情更新
rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log
set expfpath=百萬級
echo 導出%expfpath%數(shù)據(jù):
for %%i in (%sqlpath%\%expfpath%\exp*.sql) do (
set /p="導出數(shù)據(jù): %%~ni"<nul
%sqluldr% gtcustomer/passwd file=%csvpath%\%expfpath%\%%~ni.csv text=csv field=, sql=%%i log=%csvpath%\%expfpath%\%%~ni.log
echo ............ok.
)
set expfpath=千萬級
echo 導出%expfpath%數(shù)據(jù):
for %%i in (%sqlpath%\%expfpath%\exp*.sql) do (
set /p="導出數(shù)據(jù): %%~ni"<nul
%sqluldr% gtcustomer/passwd file=%csvpath%\%expfpath%\%%~ni.csv text=csv field=, sql=%%i log=%csvpath%\%expfpath%\%%~ni.log
echo ............ok.
)
pause
更多信息請查看IT技術專欄