Re: [問題] Dos AutoBatch
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 8 篇):