473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Search for files with no extension

Hi,

I need to search a particular directory for all the files that do not have
any extension and have a specific naming convension. The first 3 characters
of the file name are alpha and the rest are numeric. For example, valid files
are 'abc1234', 'xyz9876' etc. Is there a search pattern I can use with the
Directory.getFiles( ) method. Thanks in Advance

Prem

Nov 16 '05 #1
1 7221
I'm afraid Directory.GetFiles() isn't going to help you here since it only
supports two wildcards: * (one or more characters) and ? (exactly one
character). It seems to me you are going to need a regular expression to
handle the file name matching. Here's what I would do:

1. Retrieve all files in the directory using Directory.GetFiles(string
directory)

2. Parse the file list to identify all files with no extension. You can use
the FileInfo class. Whenever FileInfo.Extension returns an empty string, you
have found a file.

3. Compare the file names with no extension (FileInfo.Name) against a
regular expression. Something like [A-Za-z][A-Za-z][A-Za-z]\d+ should work.
This will look for three characters in the A-Z range (both cases) followed
by one or more decimal characters. I suppose you could go with just [a-z] if
you used FileInfo.Name.ToLower()

You're going to need the System.Text.RegularExpressions namespace for this
approach. First, create an expression:

Regex r = new Regex("[a-z][a-z][a-z]\d+", RegexOptions.Compiled);

After that you can use:

Match m = r.Match(FileInfo.Name.ToLower());

and test m.Success to see if you found a match.

I hope this helps.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"Prem" <Pr**@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
Hi,

I need to search a particular directory for all the files that do not have
any extension and have a specific naming convension. The first 3
characters
of the file name are alpha and the rest are numeric. For example, valid
files
are 'abc1234', 'xyz9876' etc. Is there a search pattern I can use with the
Directory.getFiles( ) method. Thanks in Advance

Prem

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Doe | last post by:
I realise that this is not really a python question, but python's the only language I'd be comfortable trying to deal with this. What I need is to search a drive and find all the AVI format files...
2
by: ALI-R | last post by:
I am using the follwoing code to get all files which have txt as an extension but I get an error that your search pattern is not correct.it seems this fuction dosn't accept "*.txt" as search...
2
by: John Smith | last post by:
Hello all: I am trying to search for more than one extension in a directory at the same time with the following code: string files = Directory.GetFiles(sDir, "*.doc*.dot"); However, this...
2
by: Alphonse Giambrone | last post by:
Is there a way to use multiple search patterns when calling Directory.GetFiles. For instance Directory.GetFiles("C:\MyFolder", "*.aspx") will return all files with the aspx extension. But what if...
0
by: EC | last post by:
There are times when I use the Search utility of windows explorer to find ASPX file(s) that contains a specific word. The Search utility however skips the <script ..> </script> block in the ASPX...
9
by: kd | last post by:
Hi All, I seem to have lost a vb.net project. It would be of great help if anybody could suggect a way, that I can give a windows search to look for keywords in the .vb files present in the...
0
by: Chung Leong | last post by:
Here's a short tutorial on how to the OLE-DB extension to access Windows Indexing Service. Impress your office-mates with a powerful full-text search feature on your intranet. It's easier than you...
16
by: Computer geek | last post by:
Hello, I am new to VB.NET and programming in general. I have taught myself a lot of the basics with vb.net but am still quite the novice. I am working on a little application now and I need some...
3
by: =?Utf-8?B?UGVycmlud29sZg==?= | last post by:
Not sure where to post this... Found some interesting behavior in Windows Search (Start =Search =All files and folders =search for "A word or phrase in the file:"). This applies to XP and maybe...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.