Re: Regex Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Jan 21, 2:17 pm, Tony! <n...@xxxxxxxx> wrote:
I've got a directory that contains many files with the filespec
filename#stringof14chars.wav

i.e-
"011420091557_ABC00097_400_5193760521_0008A17F_631122_002#20090114155411.wa­v"

In a database table, I find the filename minus the # and all after it
i.e- "011420091557_ABC00097_400_5193760521_0008A17F_631122_002"

I'm trying to check if the filename pulled from the database table
exists in the directory of files.

I've got
 if (File.Exists(RemoteDir + filename))
{
code

}

from where I was puilling the filenames looping through the directory
and checking for a match, but this dir is gonna grow by several
thousand every day (they back up files daily, but there is always
gonna be many thousand files there)

Figured it would be faster to get file list from table instead of
directory to speed things up, but I can't figure out the Regex syntax
to check for the filename with the full #...wav name while only having
the first part of the filename.

I ended up using this

String[] Found = Directory.GetFiles(RemoteDir, filename + "*.wav");
Which I thought would take just about as long as
String[] Filenames = Directory.GetFiles(Directory, "*.wav");

But it comes back in about a second.

But I still wonder.. for future reference., if I did do it using
Regex, how would I do it? Can I even do it using Regex?

There are no standard filesystem search functions that operate with
regexes, so you'd have to enumerate the entire directory within your
program and match your regex against it. I guess that the stock
pattern matching (with ? and *) is somehow optimized by the system at
least for the more trivial cases (e.g. for your case, where the "*"
follows some prefix string, I'd expect NTFS to use its B-tree to
lookup that prefix).

.



Relevant Pages

  • Re: To split, or to regex
    ... public static string ReplaceKeys ... I have a tag for filename, but most filenames will not be static. ... the xml file within the proper tags, with the various ways the date ... But I'm thinking Regex would be a better way to handle this and easier ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Incrementing variable with preceding zeros?
    ... The filename convention is always seven numbers, no more, no less. ... cause a wrong file name and number to be returned by ls & tail. ... Or is there another better regex way to match the 7-numbers filenames than ... never increment above 9999999. ...
    (comp.unix.shell)
  • Re: Incrementing variable with preceding zeros?
    ... The filename convention is always seven numbers, no more, no less. ... cause a wrong file name and number to be returned by ls & tail. ... Or is there another better regex way to match the 7-numbers filenames than ... never increment above 9999999. ...
    (comp.unix.shell)
  • Re: Regular expressions: how to skip characters from a capture
    ... I am trying to build a regex, which needs to capture data from a .csv ... The first part should be a filename - either enclosed in quotes, ...
    (comp.lang.perl.misc)
  • Re: how the print the first 7 letter of file name
    ... I was not trying to come up with an altenative regex to do what he might ... have wanted (first 7 characters or filename up to the underscore) ... So I modified your regex to extract the pathname and throw away the basename ...
    (perl.beginners)