Hey guys...Finished my other projects and working on a new one..A File Deleting program...Eventually I want to work up to where people can register it but for now I have to work on deleting multiple unnamed files at once. Lets say I have 50 text files no particular names in the directory C:\Program Files\Engine\Run\ and I want to delete all of them with the click of a button. I have tried using the DeleteFile function but it can only delete files with specific names. Any other functions or procedures anyone would suggest? Any help is MUCH appreciated.

RIF
Posted on 2002-07-08 00:02:16 by resistance_is_futile
you would need to go thru the directory with FindFirstFile/FindNextFile and use DeleteFile on each name returned.
Posted on 2002-07-08 00:21:47 by Kudos
Do I need to store the names in a buffer? Or do I just use FindFirstFile to get the file name then after it finds it use deletefile to delete it and then go onto the next file?
Posted on 2002-07-08 00:29:04 by resistance_is_futile
I would use the SHFileOperation APIs...

It is very customizable and you can delete names with wildcards... (*.txt, *.*)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/reference/structures/shfileopstruct.asp

It would also be hell a lot faster than using findfirst/findnextfile and DeleteFile for each file imho...
Posted on 2002-07-08 00:53:54 by JCP
I chucked together this quick bit of code (mixed with pseudo code) on how to do this:

[size=12]

db szPath "C\:Program Files\Microsoft s-h-i-t\*.*", 0
db szTextFiles "C\:Program Files\Microsoft s-h-i-t\*.txt", 0


LOCAL foundData :WIN32_FIND_DATA
LOCAL currentFileHandle :DWORD

invoke FindFirstFile, ADDR szPath, ADDR foundData
.IF eax
.WHILE eax
mov curentFileHandle, eax

;check the file name returned in foundData.cFileName
...do whatever you need to do to check file name...

;if okay to delete (not locked, or on ignore list, etc.)
invoke DeleteFile, ADDR [foundData.cFileName]

.IF eax
;delete was successful

.ELSE
;delete failed
;raise error, log error, whatever
.ENDIF

...fill foundData.cFileName with NULLs before reusing...
...fill foundData.cAlternateFileName with NULLs before reusing...

mov eax, currentFileHandle
invoke FindNextFile, eax, ADDR foundData
.WEND
.ELSE
;there was no files found....
...do stuff...
.ENDIF
[/size]


Note the paths in the code, by adjusting the bit at the end you can control what to look for and therefore delete. Also note that the code above doesn't go into subdirectories (remember i just chucked it together), if you can't work out that bit let me know and i will post a generic routine i have which finds files recursively.
Posted on 2002-07-08 01:06:57 by sluggy
It is very customizable and you can delete names with wildcards... (*.txt, *.*)
That could be a good option.

It would also be hell a lot faster than using findfirst/findnextfile and DeleteFile for each file imho...
I dunno about that, i have got some good performance out of those APIs, it would be interesting to compare the two methods one day.
Posted on 2002-07-08 01:10:23 by sluggy
You shouldn't delete files while you are searching for them. Otherwise, some files may be overlooked. Instead, store away all the filenames in memory and then delete them after you closed the search.
Posted on 2002-07-08 19:02:15 by Sephiroth3

You shouldn't delete files while you are searching for them. Otherwise, some files may be overlooked. Instead, store away all the filenames in memory and then delete them after you closed the search.


How is that?
Posted on 2002-07-08 23:20:14 by comrade
It may not apply to all of the file systems, but when you delete the file you just found, then the rest of the files will shift up by one row, including the file that Windows was going to tell you about next. That way, it skips every other file. Somebody had problems with this on another board as well.
Posted on 2002-07-09 01:33:13 by Sephiroth3
Want to know the quick dirty way of doing it, because if you don't you have to create a linked list, and use the DeleteFile after you've searched all the necessary files to be deleted(costs memory, time, size of code...)

Solution:
    [*]dynamically create a .bat file with the necessary code (E.G.) del *.txt
    [*]Use ShellExecute to run the .bat file.
    [*]Your done.:)
Posted on 2002-07-09 02:14:16 by stryker