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?
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.
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..............