473,729 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching a folder for certain files

13 New Member
Hello, is there a way to search a folder for certain files containing a wildcard or certain text entered into a text box. Right now all i can get is the whole list of files from a folder using the following code:

lstbox.additems .addrange(IO.di rectory.getfile s("c:\"))

How can i just return only files with matching text as whats in the text Box. Any help will be greatly appreciated. Thanks.

Matt
Feb 26 '08 #1
15 2445
Dököll
2,364 Recognized Expert Top Contributor
Hello, is there a way to search a folder for certain files containing a wildcard or certain text entered into a text box. Right now all i can get is the whole list of files from a folder using the following code:

lstbox.additems .addrange(IO.di rectory.getfile s("c:\"))

How can i just return only files with matching text as whats in the text Box. Any help will be greatly appreciated. Thanks.

Matt
Hello spazzo6281!

Here is what I pulled up at microsoft:

Expand|Select|Wrap|Line Numbers
  1. Dim MyFile, MyPath, MyName
  2. ' Returns "WIN.INI"  if it exists.
  3. MyFile = Dir("C:\WINDOWS\WIN.INI")   
  4.  
  5. ' Returns filename with specified extension. If more than one *.ini
  6. ' file exists, the first file found is returned.
  7. MyFile = Dir("C:\WINDOWS\*.INI")
  8.  
  9. ' Call Dir again without arguments to return the next *.INI file in the 
  10. ' same directory.
  11. MyFile = Dir
  12.  
  13. ' Return first *.TXT file with a set hidden attribute.
  14. MyFile = Dir("*.TXT", vbHidden)
  15.  
  16. ' Display the names in C:\ that represent directories.
  17. MyPath = "c:\"   ' Set the path.
  18. MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
  19. Do While MyName <> ""   ' Start the loop.
  20.    ' Ignore the current directory and the encompassing directory.
  21.    If MyName <> "." And MyName <> ".." Then
  22.       ' Use bitwise comparison to make sure MyName is a directory.
  23.       If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
  24.          Debug.Print MyName   ' Display entry only if it
  25.       End If   ' it represents a directory.
  26.    End If
  27.    MyName = Dir   ' Get next entry.
  28. Loop
  29.  
http://msdn2.microsoft.com/en-us/library/aa262726.aspx

Try it, see if that works for ya;-)

In a bit!
Feb 26 '08 #2
spazzo6281
13 New Member
That didn't work, I'm just going to have to keep looking. Thanks for the help though.
Feb 27 '08 #3
Killer42
8,435 Recognized Expert Expert
See here. The getfiles() method supports searching for files matching a wildcard specification.
Feb 27 '08 #4
basti42
18 New Member
you can try this

dirs = Directory.GetFi les("C:\\folder s", "*" + txtSeek.Text + "*" + ".csv");
foreach (string dir in dirs)
{
listBox1.Items. Add(dir.Substri ng(34));
strFound = dir;
Directory.Creat eDirectory("C:\ \save_to);
File.Copy(strFo und, "C:\\save_t o\\, true);
}
Feb 27 '08 #5
spazzo6281
13 New Member
I was finally able to get most of the code figured out with the following:

Dim find As String = txtSearch.Text

For Each foundfile As String In My.Computer.Fil eSystem.GetFile s("t:\documents ", FileIO.SearchOp tion.SearchAllS ubDirectories, find + "*.pdf", find + "*.doc")
lstBox.Items.Ad d(foundfile)
Next

it works to find files that start with a given letter or the given first work but i won't find items if the word is second or third in the file name. if anyone can help me figure out how to do that I would greatly appreciate it. Thanks for that that helped on my first post.
Mar 11 '08 #6
Killer42
8,435 Recognized Expert Expert
Just concatenate another "*" before find.
Mar 11 '08 #7
spazzo6281
13 New Member
Just concatenate another "*" before find.
Thanks, that worked.
Mar 11 '08 #8
Killer42
8,435 Recognized Expert Expert
Thanks, that worked.
Excellent! :)

Glad we could help.
Mar 11 '08 #9
spazzo6281
13 New Member
Thanks to everyone that helped with this problem. Now that it's working all the found files come back like "t:\photos\*.jp g" does anybody out there know of a way to remove "t:\photos\ " and still have the "process.start( lstbox.text)" function work. I've tried everything that i could think of, and I guess I don't even know if it's possible. If anyone has any ideas I would appreciate it. Thanks.
Mar 12 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2531
by: John | last post by:
Hi everyone ! This is a first time I post a message here. If I post my message in a wrong group. Please ignore it. I am trying to build a website which allows users (can be thousands of users, supposedly) to upload their files to their designaged directories (max 15 files for each user). A super user (can be more than one) want to search for a particular file name and also a particular textual part of a file of all user's files in all...
4
1400
by: Les Juby | last post by:
Can anyone please help with some VBScripting that would enable me to search thru Word documents (Word 2000 format) and return the filenames to use in a archive search on a legal website.? TIA .les. o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o Les Juby lesjuby@anti-spam.iafrica.com
1
1167
by: PHPGB | last post by:
While I know putting a app into a folder was chiseled out of fine scottish granite and carried upto the top of ben nevis by php newbies many years ago - I dont think a folder is the best way to do it . The fact a script is in a folder means certain instant problems if you want to do certain things with . Assuming a script doesnt have index.php and all the script files have a filename prefix like phpgb_ then theres no chance of them...
29
2652
by: jaysherby | last post by:
I'm new at Python and I need a little advice. Part of the script I'm trying to write needs to be aware of all the files of a certain extension in the script's path and all sub-directories. Can someone set me on the right path to what modules and calls to use to do that? You'd think that it would be a fairly simple proposition, but I can't find examples anywhere. Thanks.
1
1912
by: halcyon943 | last post by:
have 4 folders that I watch and need to move files from to another location. Three constraints: -Finish time. Make sure the program stops transferring files at a specific time -Number of files transferred. Can only move a certain amount of files per time period. -Folders have a priority. The files have to be moved based on the folder priority.
5
1847
by: bir | last post by:
I have a folder which contains the xml files with the word CICM in the filename (can also contain some other files) I need to search for all these xml files and create a single zip file for all these xml's. Currently i tried searching using the $File::Find. Please correct me in my code here or else if there's any other better option available. #Searching for the CICM files in CICM data folder find(sub { return if ($_ =~/^CICM/i);
8
1570
by: jcopeland38053 | last post by:
I have a third party program that runs several scheduled batch routines every night. Each type of batch routine creates a folder in the C:\Temp directory. Inside the folders are error reports that are txt files. I am writing a program that will also be run as a scheduled routine, but it will look for the most recent set of folders (tg*, ar*, mdb* are the folder strings) and read the txt files looking for certain strings. If the strings exist...
0
1465
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I've migrated from Win 2003 server to Win 2008 server. I've been banging my head agaist a wall for several days now trying to figure this out. I have the following script that will search the file system and return file names of all files within a folder and subfolders that meet the search criteria of DateLastModified. To test the output, you can use the following link:
1
1381
by: coolheadash | last post by:
Hi all, I have a folder named "folder" having multiple files inside different nested folders. Many files under it have a certain text that i am looking for. Before this line, I have to add a line and save it. The certain text is something like: return xyz; } If its this I want to add a line just before return xyz;
0
8921
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
8763
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
9284
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
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
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
4528
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...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
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.