作者x2006 (小帅 ^^)
看板Programming
标题Re: [问题] Dos AutoBatch
时间Fri Feb 1 00:45:28 2008
真奇怪 , 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
1F:推 oohay:请看我1/18同标题文章及LPH66大的推文回答 59.112.229.16 02/01 02:31
2F:→ x2006:看不懂,有范例吗? 61.229.115.49 02/01 03:41
3F:→ MOONRAKER:累死了,我宁愿装个bash来用 X( 59.115.195.209 02/01 05:48
4F:→ MOONRAKER:(还真的有这种部份功能的win32 bash) 59.115.195.209 02/01 18:50