目录中的文件数 [英] Number of files in a directory

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

问题描述

我试图仅在一行中查找目录中文件的数量(* .rar).

I'm try to find, in only one row, the number of files (*.rar) in a directory.

为此,我使用以下命令:

For doing this I'm using the commands:

for /f "delims=" %i in ('find /c ".rar" "D:\backup e ckpdb ept-icd\test\unload\lista_files_rar.txt"') do echo %i

但是最后我拥有的%i的值是:D:\ BACKUP E CKPDB EPT-ICD \ TEST \ UNLOAD \ LISTA_FILES_RAR.TXT:8

but the value of %i I have at the end is : D:\BACKUP E CKPDB EPT-ICD\TEST\UNLOAD\LISTA_FILES_RAR.TXT: 8

我只想获取数字8,所以我回显值是将值分配给变量.

I would like to obtain only the number 8 so instead to echo the value I would assign the value to a variable.

我使用命令行:dir/b * .rar |找到/c".rar" 它返回目录中rar文件的值,但是我不能将值分配给变量,例如:dir/b * .rar |查找/c".rar" |设置/一个文件=

I use the command line : dir /b *.rar | find /c ".rar" that it returns the value of rar files in the directory, but I can't assign the value to a variable, for example: dir /b *.rar | find /c ".rar" | set/a files =

我也尝试使用关键字tokens = 2,但这不起作用

I tried also to use the keyword tokens=2 but it doesn't work

p.s如果可能仅使用find命令可以做到这一点也更好

p.s If it possible to do it only with the find command is also better

推荐答案

例如,请参见此处在计数文件上

See here for example on counting files

或者您可以只做类似的事情(未经测试)

Or you can simply do something like this (not tested)

for /F %%j in ('dir /B *.rar ^| find /C /V ""') do set count=%%j

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

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