Archive: remove every occurance of "file" in a directory?


remove every occurance of "file" in a directory?
recursively removing a file named "empty_directory" that is exactly 0 bytes in size...

how do i do this?

e.g.
dir1\
dir1\dir2\empty_directory
dir1\dir3\
dir1\dir4\empty_directory

I want all of these "empty_directory" files removed with as few commands as possible! :)

oh and need i mention i have no idea where these files actually are so removing them "manually" is not an option


Check out NSIS User Manual, Appendix E: Useful Headers, E.1.2 Locate


Such a thing you're looking for, can be done easily with locate. I believe that if you wait for a while, it's most likely that Instructor will post here a working example showing how to perform the whole thing.

Edit:
This thread has working examples.


OK, this should do the job.

# works for files in the same HDD where your application has been installed.
# assumes that application's path is in registry to grab it from there.
# recursively find / remove all files with specified name & zero byte

!define MY_APP_LOCATION "Software\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe"

Name "Find and Delete"
OutFile "Find_Delete.exe"
ShowInstDetails show

!include "FileFunc.nsh"

!insertmacro GetRoot
!insertmacro Locate

var APP_PATH

Function LocateCallBack
StrCpy $R0 $R9
StrCpy $0 StopLocate
Push $0
FunctionEnd

Section -
ReadRegStr $1 HKLM "${MY_APP_LOCATION}" ''
StrCmp $1 '' +1 +2
messagebox mb_ok "$$1 application's location not found" IDOK _end
${GetRoot} "$1" "$APP_PATH"
_loop_until:
${Locate} "$APP_PATH" "/L=F /M=dummy.txt /S=0:0B" "LocateCallBack"
IfErrors +1 +2
MessageBox MB_OK 'Error!' IDOK _end
messagebox mb_ok '$R0'
StrCmp $R0 '' +1 +2
MessageBox MB_OK "File(s) Not found" IDOK _end
Delete $R0
StrCpy $R0 ''
goto _loop_until
_end:
SectionEnd

Name "Output"
OutFile "Output.exe"

!include "FileFunc.nsh"
!insertmacro Locate

Section
${Locate} "C:\dir1" "/L=F /M=empty_directory /S=0:0B" "LocateCallback"

IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd

Function LocateCallback
Delete $R9

Push $0
FunctionEnd