file find first/next function in C#?

This is a discussion on file find first/next function in C#? within the C# Programming forums, part of the General Programming Boards category; I searched for a long time now, msdn google ect., and found nothing like it. I need to search for ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    file find first/next function in C#?

    I searched for a long time now, msdn google ect., and found nothing like it.

    I need to search for a file that has the sting in it.

    So like if I said to find all files that have "virus" in there name, it would return the paths of the first file found. Then I can use somthing like fileFindNext to get the next file. And so on.



    And I will give a reason why right now....

    I am making a semi tracking cookie protection. It will be weak but good enough for me. Might cover some bad viruses as well.

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    nvm

    Though if somone does know one it would help but nothing will suit my needs.

    So I created my own. It works perfectly and just how I want it.

    I used my BOOK to help me out. My book has a who section on Directories, Files, Asynchronous I/O, Netword I/O, Web Streams, Serialization, and Isolated Storage.

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Yeah you'd basically do:
    Code:
    string[] files = System.IO.Directory.GetFiles(path, "*virus*");
    foreach (string f in files)
    {
        // do what you want with the file now you have it's name
    }
    However to search all directories you'd have to use some recursion, I can provide a sample later if you want.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok fine mister "I am better than mister Alex". My way has more code, which therefore could be slower.

    Code:
                DirectoryInfo dir = new DirectoryInfo(@"C:\Documents and Settings\Alex\Cookies");
                FileInfo[] filer = dir.GetFiles();
                int length = filer.Length;
                int i = 0;
                while (i != length)
                {
                    i += 1;
                    string name = filer[i].Name;
                    if (name.Contains("text to find here"))
                    {
                        MessageBox.Show("Found cookie!");
                    }
                }
    I will see what I can do with these codes. And nah I don't need an example, my book teaches recursion though directories in the windows form section.


    Edit: And no I am not being mean, it is in a friendly way.
    Last edited by Rune Hunter; 03-07-2005 at 06:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. error LNK2001: unresolved external symbol
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 07-12-2002, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21