计算文件名中包含某个字符串的文件? [英] counting files that contain a certain string in the filename?

查看:97
本文介绍了计算文件名中包含某个字符串的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算某个目录中的文件,该目录中包含字符串-Contract

Template.xml。我该怎么做?

I need to count files in a certain directory that has the string -Contract
Template.xml at the end of it. How would I do this?

推荐答案

尝试类似的事情:


Dim _files = Directory.GetFiles(_path)


Dim _count = 0

For _ file in _files

if _file。 EndsWith(" -Contract Template.xml")然后_count + = 1

下一页

" Andy B" < a _ ***** @ sbcglobal.netwrote in message

news:e1 ************** @ TK2MSFTNGP04.phx.gbl ...
Try something like:

Dim _files = Directory.GetFiles(_path)

Dim _count = 0

For Each _file In _files
If _file.EndsWith("-Contract Template.xml") then _count += 1
Next
"Andy B" <a_*****@sbcglobal.netwrote in message
news:e1**************@TK2MSFTNGP04.phx.gbl...

>我需要计算某个目录中的文件,其中包含字符串-Contract
Template.xml。我该怎么做?
>I need to count files in a certain directory that has the string -Contract
Template.xml at the end of it. How would I do this?


6月29日,9:28 * pm,Stephany Young < noone @ localhostwrote:
On Jun 29, 9:28*pm, "Stephany Young" <noone@localhostwrote:

尝试类似的事情:


* Dim _files = Directory.GetFiles(_path)


* Dim _count = 0

*对于每个_file在_files

* *如果_file.EndsWith(" -Contract Template.xml")然后_count + = 1

*下一页


" Andy B" < a_bo ... @ sbcglobal.netwrote in message


news:e1 ************** @ TK2MSFTNGP04.phx.gbl ...
Try something like:

* Dim _files = Directory.GetFiles(_path)

* Dim _count = 0

* For Each _file In _files
* * If _file.EndsWith("-Contract Template.xml") then _count += 1
* Next

"Andy B" <a_bo...@sbcglobal.netwrote in message

news:e1**************@TK2MSFTNGP04.phx.gbl...

我需要计算某个目录中的文件,其中包含字符串-Contract

Template.xml。我该怎么做?
I need to count files in a certain directory that has the string -Contract
Template.xml at the end of it. How would I do this?



或者你可以在没有循环的情况下完成:


///////// ////////////////

Dim fileCount As Integer = Directory.GetFiles(path," * - Contract

Template。 xml)。长度

/////////////////////////


如果需要,您还可以选择搜索子目录:


/////////////////////////

Dim totalFileCount As Integer = Directory.GetFiles(path," * - Contract

Template.xml",SearchOption.AllDirectories).Length

/////////////////////////


谢谢,


Seth Rowe [MVP]

Or you could do it without the loop:

/////////////////////////
Dim fileCount As Integer = Directory.GetFiles(path, "*-Contract
Template.xml").Length
/////////////////////////

You also have the option to search sub directories if need be:

/////////////////////////
Dim totalFileCount As Integer = Directory.GetFiles(path, "*-Contract
Template.xml", SearchOption.AllDirectories).Length
/////////////////////////

Thanks,

Seth Rowe [MVP]


是的,更正Seth,但你可能会被记录在案中的不良3字符

扩展行为在

Directory.GetFiles方法的文档中。


给定一个文件名为的目录:


A123 -Contract Template.xml

A123-Cont使用:


Directory.GetFiles(path," * - Contract Template.xml")。 $>

将导致计数为2,而使用循环将获得正确的

计数。

" rowe_newsgroups" < ro ******** @ yahoo.com写了留言

news:37 ********************** ************ @ i76g2000 hsf.googlegroups.com ...

6月29日晚9:28,Stephany Young < noone @ localhostwrote:
Yes, correct Seth, but you could get bitten by the undesirable 3 character
extension behaviour that is documented in the documentation for the
Directory.GetFiles method.

Given a directory with files named:

A123-Contract Template.xml
A123-Contract Template.xmla

using:

Directory.GetFiles(path, "*-Contract Template.xml").Length

would result in a count of 2, whereas using a loop will get the correct
count.
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:37**********************************@i76g2000 hsf.googlegroups.com...
On Jun 29, 9:28 pm, "Stephany Young" <noone@localhostwrote:

尝试类似:


Dim _files = Directory.GetFiles(_path)


Dim _count = 0


每个_file在_files

如果_file.EndsWith(" -Contract Template.xml" ;)然后_count + = 1

下一页


" Andy B" < a_bo ... @ sbcglobal.netwrote in message


news:e1 ************** @ TK2MSFTNGP04.phx.gbl ...
Try something like:

Dim _files = Directory.GetFiles(_path)

Dim _count = 0

For Each _file In _files
If _file.EndsWith("-Contract Template.xml") then _count += 1
Next

"Andy B" <a_bo...@sbcglobal.netwrote in message

news:e1**************@TK2MSFTNGP04.phx.gbl...

我需要计算具有

字符串的某个目录中的文件-Contract

Template.xml在它的最后。我该怎么做?
I need to count files in a certain directory that has the
string -Contract
Template.xml at the end of it. How would I do this?



或者你可以在没有循环的情况下完成:


///////// ////////////////

Dim fileCount As Integer = Directory.GetFiles(path," * - Contract

Template。 xml)。长度

/////////////////////////


如果需要,您还可以选择搜索子目录:


/////////////////////////

Dim totalFileCount As Integer = Directory.GetFiles(path," * - Contract

Template.xml",SearchOption.AllDirectories).Length

/////////////////////////


谢谢,


Seth Rowe [MVP]

Or you could do it without the loop:

/////////////////////////
Dim fileCount As Integer = Directory.GetFiles(path, "*-Contract
Template.xml").Length
/////////////////////////

You also have the option to search sub directories if need be:

/////////////////////////
Dim totalFileCount As Integer = Directory.GetFiles(path, "*-Contract
Template.xml", SearchOption.AllDirectories).Length
/////////////////////////

Thanks,

Seth Rowe [MVP]


这篇关于计算文件名中包含某个字符串的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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