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.directory.getfiles("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
15 2414
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.directory.getfiles("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: -
Dim MyFile, MyPath, MyName
-
' Returns "WIN.INI" if it exists.
-
MyFile = Dir("C:\WINDOWS\WIN.INI")
-
-
' Returns filename with specified extension. If more than one *.ini
-
' file exists, the first file found is returned.
-
MyFile = Dir("C:\WINDOWS\*.INI")
-
-
' Call Dir again without arguments to return the next *.INI file in the
-
' same directory.
-
MyFile = Dir
-
-
' Return first *.TXT file with a set hidden attribute.
-
MyFile = Dir("*.TXT", vbHidden)
-
-
' Display the names in C:\ that represent directories.
-
MyPath = "c:\" ' Set the path.
-
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
-
Do While MyName <> "" ' Start the loop.
-
' Ignore the current directory and the encompassing directory.
-
If MyName <> "." And MyName <> ".." Then
-
' Use bitwise comparison to make sure MyName is a directory.
-
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
-
Debug.Print MyName ' Display entry only if it
-
End If ' it represents a directory.
-
End If
-
MyName = Dir ' Get next entry.
-
Loop
-
http://msdn2.microsoft.com/en-us/library/aa262726.aspx
Try it, see if that works for ya;-)
In a bit!
That didn't work, I'm just going to have to keep looking. Thanks for the help though.
See here. The getfiles() method supports searching for files matching a wildcard specification.
you can try this
dirs = Directory.GetFiles("C:\\folders", "*" + txtSeek.Text + "*" + ".csv");
foreach (string dir in dirs)
{
listBox1.Items.Add(dir.Substring(34));
strFound = dir;
Directory.CreateDirectory("C:\\save_to);
File.Copy(strFound, "C:\\save_to\\, true);
}
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.FileSystem.GetFiles("t:\documents", FileIO.SearchOption.SearchAllSubDirectories, find + "*.pdf", find + "*.doc")
lstBox.Items.Add(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.
Just concatenate another "*" before find.
Just concatenate another "*" before find.
Thanks, that worked.
Thanks, that worked.
Excellent! :)
Glad we could help.
Thanks to everyone that helped with this problem. Now that it's working all the found files come back like "t:\photos\*.jpg" 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.
This one should be relatively simple. Just have a look at the different properties available from the File object. I believe you'll find that one provides the name without the path. At present you're just using the default property, which apparently must be the full path.
This one should be relatively simple. Just have a look at the different properties available from the File object. I believe you'll find that one provides the name without the path. At present you're just using the default property, which apparently must be the full path.
I've looked and tried everything i could think of and it still doesn't work. I can use the trimstart feature but then the "process.start(lstbox.text)" doesn't work. I'm currently using "lstbox.items.addrange(IO.directory.getfiles("t:\p hotos"))" to get the list of files but i still can't get path to know show up and have process.start still work. Thanks for trying.
I've looked and tried everything i could think of and it still doesn't work. I can use the trimstart feature but then the "process.start(lstbox.text)" doesn't work. I'm currently using "lstbox.items.addrange(IO.directory.getfiles("t:\p hotos"))" to get the list of files but i still can't get path to know show up and have process.start still work. Thanks for trying.
The path to not show up. sorry for the miss type.
How about using the FileSystem.GetDirectories method to return the collection of directory names. Then for each of those, do a FileSystem.GetFiles and concatenate the directory name at the start of each returned filename.
How about using the FileSystem.GetDirectories method to return the collection of directory names. Then for each of those, do a FileSystem.GetFiles and concatenate the directory name at the start of each returned filename.
The program is finally doing what i wanted it to do. The concat method really helped. Thanks to everyone that helped me with my problems.
Glad we could help out. :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |