Re: [批次] 設定變數的批次檔?

看板EzHotKey作者 (かつて交わした約束)時間6年前 (2017/12/17 04:23), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《sanbis (方正)》之銘言: : 想使用 rclone 來檢查 google drive 資料夾中檔案的數量 : 然後輸入到 txt 檔案中 : 而 cmd 下指令目前如下 : 先記錄要執行的指令 : 然後執行指令並將結果記錄下來 : echo rclone size GD1:/備份/xxxxxxx >> size.txt : rclone size GD1:/備份/xxxxxxx >> size.txt : 目前確定只有資料夾名稱(紅色)會有變動 : 名稱非固定 : 但是可以先列出清單 : 像這種情況下不知道能不能寫成批次檔 : 根據清單逐條載入資料夾名稱來執行命令? for /f 可以達成你要的功能; 以下截取自 for /? 的說明 ==== FOR /F ["options"] %variable IN (file-set) DO command [command-parameters] FOR /F ["options"] %variable IN ("string") DO command [command-parameters] FOR /F ["options"] %variable IN ('command') DO command [command-parameters] 或,如果使用 usebackq 選項: FOR /F ["options"] %variable IN (file-set) DO command [command-parameters] FOR /F ["options"] %variable IN ('string') DO command [command-parameters] FOR /F ["options"] %variable IN (`command`) DO command [command-parameters] file-set 可以是一或多個檔案名稱。繼續進行 file-set 中的下個 檔案之前,都已開啟、讀取及處理過每個檔案。處理程序包括讀取 檔案、將它分割成獨立的文字行,然後將每一行剖析成零或多個語 法。使用已設成找到之語法字串的變數值,呼叫 For 迴圈的內容。 依照預設,/F 會從每個檔案的每一行傳送第一個以空格分隔的權 杖。空白行會被略過。 ==== 因為你是資料已經在清單檔案裡了, 所以直接使用無引號的版本即可 如說明所說, 它是逐行讀取資料並設進變數裡 因此以你的例子一個可能的寫法是: for /f %f in (listfile.txt) do ( echo rclone size GD1:/備份/%f >> size.txt rclone size GD1:/備份/%f >> size.txt ) -- Ace Snake Santa Clover Junpei June Seven Lotus 9th man cabin kitchen casino shower operating room laboratory T H E chart captain quarter confinement torture room steam engine room cargo chapel library study incinerator Gigantic Q director office security N O N A R Y archives control laboratory pec treatment garden pantry gaulem bay rec room crew quarters infirmary lounge elevator Tenmyouji Quark Dio G A M E S Luna Phi Sigma Alice Clover K -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.195.9.46 ※ 文章網址: https://www.ptt.cc/bbs/EzHotKey/M.1513455823.A.C4E.html
文章代碼(AID): #1QDO3FnE (EzHotKey)
文章代碼(AID): #1QDO3FnE (EzHotKey)