我想用批處理實現(xiàn)向s.txt中多次分別導(dǎo)入文本例如:“aaaa,bbbb,cccc,dddd
實現(xiàn)s.txt內(nèi)效果如:
aaaabbbbccccdddd
可是echo命令每次導(dǎo)入的時候會強制換行,如:
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的內(nèi)容將是 aaaabbbbccccdddd
注1:“ >>s.txt”這里是輸出流定向的意思,把輸出流重定到了s.txt文件,“<nul ”則是把輸入流指定成了nul,所以set/p=aaaa就不用等待用戶輸入了。
其實把寫文件操作放到后面更容易讓人理解些:set /p=aaaa<nul>>s.txt
實例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
應(yīng)用:
代碼如下:
echo off
set csvpath=測試數(shù)據(jù)
set sqluldr=d:\sqluldr\sqluldr2sdk\sqluldr2
set sqlpath=導(dǎo)出模板
rem set filename=產(chǎn)品行情
rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log
rem
rem set filename=產(chǎn)品行情更新
rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log
set expfpath=百萬級
echo 導(dǎo)出%expfpath%數(shù)據(jù):
for %%i in (%sqlpath%\%expfpath%\exp*.sql) do (
set /p=導(dǎo)出數(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 導(dǎo)出%expfpath%數(shù)據(jù):
for %%i in (%sqlpath%\%expfpath%\exp*.sql) do (
set /p=導(dǎo)出數(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
關(guān)于使用attrib設(shè)置文件只讀、隱藏和系統(tǒng)屬性,本文就介紹這么多,希望對您有所幫助,謝謝!