Re: [問題] Dos AutoBatch

看板Programming作者 (小帥 ^^)時間16年前 (2008/02/01 00:45), 編輯推噓1(104)
留言5則, 3人參與, 最新討論串5/8 (看更多)
真奇怪 , DOS 裡面的 for 無法用變數 ( set /a sum = sum + 1 ) 嗎 ? 如果不使用 call check.bat , 請問大大 , DOS 如何直接在 for 裡面用變數 ( set /a sum = sum + 1 ) 呢 ? 底下程式(main.bat)可以正常的跑 , 前提是檔名(*.txt) 不能有 space 字元 . 看哪位高手要幫我修正的 ? 多謝~ main.bat -------- set sum=0 set max=10 set source=D:\test1 set destin=C:\test2 set filetype=*.txt cd /d %source% for /f %%i in ('dir %filetype% /od /b') do ( move %source%\%%i %destin% call D:\check.bat pause ) D:\check.bat ------------ set /a sum = sum + 1 if %sum% equ %max% exit ※ 引述《oohay (五黑)》之銘言: : 標題: Re: [問題] Dos AutoBatch : 時間: Fri Jan 18 22:13:03 2008 : : ※ 引述《TwoDemon (店小二)》之銘言: : : 如果將一個目錄下一次移10個檔至另一個目錄。 : : 我原來的寫法是全移: move D:\test1\*.txt C:\test2\ : : 但現在要改成一次最多只移10個檔。 : : 但,要怎麼寫成一個完整可以運作的script,希望版上高手幫幫忙,謝謝! : : 其實看熟指令之後還蠻好寫的,也不見得都只能用For. : 下面這程式要四個參數:來源目錄,檔案篩選文字,目的目錄,移檔一批數量. : 第四個參數可以不加. : : 例如,假設程式儲存為test.bat,使用的命令是: : test.bat test1 *.txt test2 : 預設移動10個檔案,如果要改成移3個檔案,就把第四個參數加進去: : test.bat test1 *.txt test2 3 : : : @echo off : rem ================ DOS shell script under Windows XP ================== : : rem ----------------------- Syntax checking ----------------------------- : if "%1" == "" echo Syntax: %0 source_directory file_type destination_directory [max_move] & goto end : if "%2" == "" echo Syntax: %0 source_directory file_type destination_directory [max_move] & goto end : if "%3" == "" echo Syntax: %0 source_directory file_type destination_directory [max_move] & goto end : : rem --------------------- Directory checking ---------------------------- : if not exist "%1" echo Argument #1 must be a directory. & goto end : if not exist %1\nul echo Argument #1 must be a directory. & goto end : if not exist "%3" echo Argument #3 must be a directory. & goto end : if not exist %3\nul echo Argument #3 must be a directory. & goto end : : setlocal : set count=0 : set max=10 : if not "%4" == "" set max=%4 : : :begin : : rem ------------------------- File checking ----------------------------- : dir /b %1\%2 > nul 2>&1 : if errorlevel 1 goto end : : for /f "usebackq" %%s in (`dir /b %1\%2`) do echo Move %1\%%s to %3 & move : %1\%%s %3 & goto stop : :stop : set /a count=count+1 : if not %count% == %max% goto begin : endlocal : : :end : : @echo on : : : : : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ◆ From: 59.112.225.149 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.229.115.49

02/01 02:31, , 1F
請看我1/18同標題文章及LPH66大的推文回答
02/01 02:31, 1F

02/01 03:41, , 2F
看不懂,有範例嗎?
02/01 03:41, 2F

02/01 05:48, , 3F
累死了,我寧願裝個bash來用 X(
02/01 05:48, 3F

02/01 18:50, , 4F
(還真的有這種部份功能的win32 bash)
02/01 18:50, 4F

02/01 18:51, , 5F
文章代碼(AID): #17eViffj (Programming)
文章代碼(AID): #17eViffj (Programming)