如何计算文件夹中的文件 [英] How to count files in a folder

查看:62
本文介绍了如何计算文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用cmd计数文件夹中的文件时,以下代码集给出了不同的结果。您能告诉我一种正确的方法吗?

When I use cmd to count the files in a folder, the following set of codes give different results. Can you show me a correct method?

 @echo off
setlocal EnableDelayedExpansion
set aa=0
for %%s in ("F:\*.*") do (
        set /a aa=!aa!+1        
)
echo !aa!

set aa=0
 for %%s in ("F:\*.*") do (
     set /a aa=!aa!        
)
echo !aa!
endlocal

set aa=0
for %%s in ("F:\*.*") do (
      set /a aa=%aa%+1        
)
echo %aa%

set aa=0
for %%s in ("F:\*.*") do (
       set /a aa=%aa%       
)
echo %aa%

pause


推荐答案

这两个代码段将计算F中的可见文件:\

These two snippets will count the visible files in F:\

@echo off
setlocal EnableDelayedExpansion
set aa=0
for %%s in ("F:\*.*") do (
        set /a aa+=1        
)
echo !aa!

在上述情况下,您还可以使用以下命令:

For the case above, you can also use this:

@echo off
set aa=0
for %%s in ("F:\*.*") do (
        set /a aa+=1        
)
echo %aa%

这篇关于如何计算文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆