iT邦幫忙

0

bat檔列出資料夾與子資料夾所有的檔案總數量

請問各位大大

如何用bat取得某資料夾與子資料夾下所有的檔案總數量,並輸出到txt file。
自已一開始寫的code是這樣

dir D:\test /a-h-s /s |find "個檔案">a.txt

執行的結果
https://ithelp.ithome.com.tw/upload/images/20190620/20116846TjU0DJdN4e.jpg
因為想只取得最後一筆,所以用for,但無法只取最後一筆的總檔案數量

for /f %%i in ('dir D:\05.BI /a-h-s /s^ find "個檔案"') do (Set "[total]=%%i")
Set [total]>D:\aaa.txt

請各位大大指教,謝謝

Jesse HO iT邦好手 1 級 ‧ 2019-06-21 02:19:12 檢舉
powershell>
Get-ChildItem -Path D:\Music\ -Recurse -Filter *.mp3 | measure
or
(Get-ChildItem -Path D:\Music\ -Recurse -Filter *.mp3 | measure).Count
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
蟹老闆
iT邦大師 1 級 ‧ 2019-06-20 23:50:11
最佳解答
@Echo Off
for /f %%i in ('dir D:\05.BI /a-h-s /s^| find "個檔案"') do (Set "[total]=%%i")
Echo %[total]%>D:\aaa.txt
sam1911 iT邦新手 5 級 ‧ 2019-06-24 09:11:03 檢舉

謝謝蟹老闆大大

我要發表回答

立即登入回答