News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Delete Temp files

Started by hutch--, September 11, 2006, 08:39:04 AM

Previous topic - Next topic

hutch--

I thought someone may like this as its very simple. Something in my system is dumping tmp files in the windows Temp directory and I end up with far too many in a short period. This is a quick way to solve the problem.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

;   This file is designed to place in your startup directory so that it
;   deletes temp files from the Windows Temp directory each time it starts.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL hSrch :DWORD
    LOCAL wfd   :WIN32_FIND_DATA

    chdir WinDir$()
    chdir "temp"

    fn FindFirstFile,"*.*",ADDR wfd
    mov hSrch, eax
    cmp eax, INVALID_HANDLE_VALUE
    je nxt
    invoke DeleteFile,ADDR wfd.cFileName

  @@:
    fn FindNextFile,hSrch,ADDR wfd
    test eax, eax
    jz frwd
    invoke DeleteFile,ADDR wfd.cFileName
    jmp @B

  frwd:
    invoke FindClose,hSrch

  nxt:
    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

sinsi

What about using SHFileOperation? This can delete subdirectories as well (I think) or at least recurse through them.
Or maybe a batch file  :bg

Edit later:
If you chdir into windir$() and then chdir into "temp" but "temp" doesn't exist then you will start to delete your windir...
Light travels faster than sound, that's why some people seem bright until you hear them.

hutch--

I already have recursive delete including directories but what I needed in this instance was deleting tmp files in one place so the simple code does exactly what I required.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

sinsi

Yep, I was just thinking of the "cut&paste" brigade.
Light travels faster than sound, that's why some people seem bright until you hear them.

hutch--

Here is a version incorporating sinsi's suggestion to test if the "temp" directory exists first.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

;   This file is designed to place in your startup directory so that it
;   deletes temp files from the Windows Temp directory each time it starts.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL hSrch :DWORD
    LOCAL wfd   :WIN32_FIND_DATA

    chdir WinDir$()
    chdir "temp"
    test eax, eax                           ; test if last op failed
    jz nxt                                  ; exit if no "temp" directory

    fn FindFirstFile,"*.*",ADDR wfd         ; call for 1st file name
    mov hSrch, eax                          ; save the search handle
    cmp eax, INVALID_HANDLE_VALUE           ; exit if not a valid handle value
    je nxt
    invoke DeleteFile,ADDR wfd.cFileName    ; delete first file if it exists

  @@:
    fn FindNextFile,hSrch,ADDR wfd          ; loop through any other file names
    test eax, eax
    jz frwd
    invoke DeleteFile,ADDR wfd.cFileName    ; delete and other files
    jmp @B

  frwd:
    invoke FindClose,hSrch                  ; close the search handle

  nxt:
    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

sinsi

 :U
I had visions of somebody deleting their windows directory - in XP it might not be too bad,
but in 98 is would be a bit of a problem...
Light travels faster than sound, that's why some people seem bright until you hear them.

P1

I would clean the GetTempPath directory as well.

Regards,  P1  :8)

asmfan

Hi all!)
Speaking about trash files i found that the following extensions are usually belong to garbage files. U can just try to search them and accurately(!) delete some or all of them. But be careful some files with such extensions are may be important... delete on your own risc...or cisc?;)

[attachment deleted by admin]
Russia is a weird place

GregL

Hutch,

I think I was having the same problem you are. Something was cramming acr*.tmp files in my 'C:\Documents and Settings\LocalServer' folder, there were 12 GB of them! I got a warning that my disk was getting full. After much searching on the web I think the culprit is Acrobat Reader (I had 7.05). I ran FileMon on one of the files and 'cidaemon.exe' was reading and writing to the files. 'cidaemon.exe' is part of the Windows Indexing Service. I did a search and most of the stuff I found suggested disabling the Indexing Service. I did that and the problem stopped, but I would rather have the Indexing Service on. I did another search for "acr tmp Indexing Service" and found this on the Adobe Reader Forums. I uninstalled Acrobat Reader (I'm using Foxit Reader anyway) and I turned the Indexing Service back on. So far so good, no more acr*.tmp files.

Greg

sluggy

Quote from: Greg on September 15, 2006, 03:57:16 AM
'cidaemon.exe' is part of the Windows Indexing Service. I did a search and most of the stuff I found suggested disabling the Indexing Service. I did that and the problem stopped, but I would rather have the Indexing Service on.
You don't need the indexing service, it just makes searches faster, but the Windows searching ability is flawed anyway. I have had many problems with that service locking files, which is a real PITA particularly when you are trying to build ASP.Net projects or do automated builds.

GregL

sluggy,

Yeah, I have gone back and forth over whether to leave Indexing Service on or to disable it. Some people say that you should disable it, others say that you should leave it on. I have read and heard opinions both ways. I have always decided to leave it on. I may disable it for a while and see how it goes.

This problem I was having was being caused by Adobe Reader. I have been using Foxit Reader and I like it much better, it's smaller, faster and has less negative side effects.