473,750 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getFi les( ) method. Thanks in Advance

Prem

Nov 16 '05 #1
1 7504
I'm afraid Directory.GetFi les() 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.GetFi les(string
directory)

2. Parse the file list to identify all files with no extension. You can use
the FileInfo class. Whenever FileInfo.Extens ion 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.T oLower()

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

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

After that you can use:

Match m = r.Match(FileInf o.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**@discussio ns.microsoft.co m> wrote in message
news:D7******** *************** ***********@mic rosoft.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.getFi les( ) 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
2442
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 that are NOT listed with the AVI extension. I'm looking over an old drive of mine from an old computer. I know the files were renamed with the wrong extension, but I know that they were originally AVI files. Can python do this for me? Any...
2
9691
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 pattern. Is there somebody can help me? using System; using System.IO; class Test
2
5979
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 does not work nor does something like this: string files = Directory.GetFiles(sDir, "*.doc, *.dot");
2
26922
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 I wanted all files with either an aspx OR htm extension? Any way to get that without calling the method twice? -- Alphonse Giambrone Email: a-giam at customdatasolutions dot us
0
1241
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 files when it searches for a word or phrase in a file or folder. The Search utility works fine when I change the file's extension to TXT. I am using Windows server 2003. Is this behavior of the Search utility expected when searching for a word...
9
2078
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 project? Thanks. kd
0
4236
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 think. First, download and install the extension (http://sourceforge.net/project/showfiles.php?group_id=171247&package_id=198554). Simply unzip the file and copy the correct version of php_oledb.dll into the PHP extensions folder. Then add the...
16
2859
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 help with one part of the code. When a button is clicked I need to have it go out to a network drive location and count how many files are present with a certain file extension. Then store that number in a declared variable. Is this possible? Can...
3
3558
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 other Windows flavors. Procedure: 1. Create a simple text file named test.txt. 2. Open the text file in a text editor and add a simple test word such as "blah" (not quotes).
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8264
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6810
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.