Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 11-03-2007, 07:26 PM   #1 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default File Search?

In a nut shell what I want to do is this:
1. Ask user for file name.
2. Search entire computer for file.
3. Execute that file.

How?
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 03-24-2008, 08:01 AM   #2 (permalink)
Forum Expert
 
Join Date: Dec 2003
Location: Sitting in a chair fulfilling my life's goal
Age: 22
Posts: 2,650
Send a message via AIM to Killamus Send a message via MSN to Killamus
Default

Code:
string name == "";
while ( !name.Contains("."))
{
Console.WriteLine("Please enter a file name: ");
name = Console.ReadLine();
}
List<string> paths = new List<string>();
paths.AddRange( Directory.GetFiles( "C:", string.Format("{0}", name), SearchOption.AllDirectories ) );
__________________
Procrastinators unite!
Tomorrow.
Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders.
Killamus is offline   Reply With Quote
Old 03-24-2008, 01:51 PM   #3 (permalink)
RunUO Forum Moderator
 
daat99's Avatar
 
Join Date: Dec 2004
Location: Israel
Age: 27
Posts: 8,163
Send a message via ICQ to daat99 Send a message via AIM to daat99
Default

Quote:
Originally Posted by Killamus View Post
Code:
string name == "";
while ( !name.Contains("."))
{
Console.WriteLine("Please enter a file name: ");
name = Console.ReadLine();
}
List<string> paths = new List<string>();
paths.AddRange( Directory.GetFiles( "C:", string.Format("{0}", name), SearchOption.AllDirectories ) );
People should notice that this code expects the file name to have a "dot" in it, that means you can't search for file names that doesn't.

Also this code doesn't make sure the file is an executable (for example I want to run file "run.me.exe" and I insert by accident "run.me", the code will look for the wrong file).

Considering you want to execute the file then this code will do the job intended.
However, I wanted to point out those things in case anyone else will want it to do a file search in general and will grab this code as is.

In any case good job Killamus, keep it up
__________________
I always try to help
Sometimes, I don't know how....

My Web Page
Forum Rules
-------------------------------------------------------------
Extensive OWLTR System | Token System | World Teleporters
-------------------------------------------------------------
daat99 is offline   Reply With Quote
Old 03-27-2008, 02:22 AM   #4 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,822
Default

you can use DirectoryInfo.GetFiles(), this function allows a search parameter such as *.txt or myfile*.txt and so on.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5