Re: counting files that contain a certain string in the filename?
- From: rowe_newsgroups <rowe_email@xxxxxxxxx>
- Date: Mon, 30 Jun 2008 08:34:48 -0700 (PDT)
On Jun 30, 9:48 am, "Andy B" <a_bo...@xxxxxxxxxxxxx> wrote:
This is right. I needed something with the EndsWith method since I wanted to
ignore files with extensions like xmla and all those oddballs that would
possibly pose as a security problem as well as invalid file formats. Only
files that end in "-Contract Template.xml" are valid filenames. The next
part of a valid file for loading is to make sure the files with the
"-Contract Template.xml" ending conform to a particular xml schema that is
created with a dataset. Just having a particular ending won't work. Since I
have the filename test done (it did work btw), now it's time to move on to
the valid xml schema is/is not valid test. Another post said to just try
loading the files into a dataset in a try...catch block. Is this right? or
is there a better way to do it?
"Stephany Young" <noone@localhost> wrote in message
news:uzs7yeq2IHA.3780@xxxxxxxxxxxxxxxxxxxxxxx
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" <rowe_em...@xxxxxxxxx> wrote in message
news:37fc6de7-a5eb-4506-ac67-69d52c199121@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jun 29, 9:28 pm, "Stephany Young" <noone@localhost> wrote:
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...@xxxxxxxxxxxxx> wrote in message
news:e127w2k2IHA.4672@xxxxxxxxxxxxxxxxxxxxxxx
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?
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]
.NET actually exposes a class / method to validate an Xml file against
a schema. It's been a long, long time since I've used it, but it's
called something like XmlSchemaValidation. If you can't find it let me
know and I'll try to find the project I used it on. This should be
substantially lighter weight than creating a dataset/datatable and
using a try...catch block.
Thanks,
Seth Rowe [MVP]
.
- Follow-Ups:
- Re: counting files that contain a certain string in the filename?
- From: rowe_newsgroups
- Re: counting files that contain a certain string in the filename?
- References:
- counting files that contain a certain string in the filename?
- From: Andy B
- Re: counting files that contain a certain string in the filename?
- From: Stephany Young
- Re: counting files that contain a certain string in the filename?
- From: rowe_newsgroups
- Re: counting files that contain a certain string in the filename?
- From: Stephany Young
- Re: counting files that contain a certain string in the filename?
- From: Andy B
- counting files that contain a certain string in the filename?
- Prev by Date: Re: Problems with programmatically added control - can't get properties, can't even reference control!
- Next by Date: Re: counting files that contain a certain string in the filename?
- Previous by thread: Re: counting files that contain a certain string in the filename?
- Next by thread: Re: counting files that contain a certain string in the filename?
- Index(es):
Relevant Pages
|