Thread: Find, search, delete

  1. #1
    Registered User
    Join Date
    Jun 2009

    Find, search, delete

    I'm making a program for my friend's Garry's Mod server that will delete files with certain names in a given directory. I'm not sure as to how I can find file/directory names, and I'm a bit iffy on searching. Plus, up until now I've just been working with Linux.

    How do I get multiple levels (say 3) of contents of a directory, the search for keywords?

  2. #2
    Registered User
    Join Date
    Mar 2007
    The functions you want to look up (on MSDN probably) are...


    These can find directories and files. Making a recursive function is pretty useful for searching. Scan a directory. When it comes across another directory, call the function again with that directory name. If it's a file, do what you wish.

  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer
    To search for files use FindFirstFile(), FindNextFile() and FindClose() [GetLastError() will help]

    Use a filter on file extension ie "*.txt"

    One call to FindFirstFile() sets up the process. Then keep calling FindNextFile() until an error occurs. You must check for the error 'ERROR_NO_MORE_FILES' to ensure we have found all the files.

    If subfolders are to be searched, I create a recursive function which takes the folder path and file filter.

    You can determine folders from the WIN23_FIND_DATA dwFileAttibutes (contains FILE_ATTRIBUTE_DIRECTORY)

    EDIT: Beaten to it..............
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Search function not working fully
    By tabstop in forum C Programming
    Replies: 7
    Last Post: 12-04-2008, 02:57 AM
  2. Delete Function in Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 5
    Last Post: 11-15-2008, 04:30 PM
  3. Proper Usage of the delete Operator
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 04-25-2007, 11:53 PM
  4. Won't Return pointer, i can't find why...
    By ss3x in forum C++ Programming
    Replies: 2
    Last Post: 02-28-2002, 08:50 PM