Archive: Search for a File on entire System


Search for a File on entire System
Hi All,

I know that there is Code available for the following:

(1) Find what drives are available on a System.

(2) Search for a File in a particular Drive



Now I want to Search for a File in all Drives i.e. I want to integrate the above two programs.
How can I do that. (Please see the attached ZIP File for above 2 programs)


By the way, is there any code already available that can SEARCH FOR A FILE IN ALL THE AVAILABLE DRIVES AND GIVE THE LOCATION WHERE THE FILE WAS FOUND
(If such a Code is found, no need to integrate above 2 Programs).


Note: My requirement is to integrate above 2 programs and search for a File. Because it will search one Drive at a time. Help me in integrating both the programs.


Attaching the 2 Programs....



-Sreedhar


Attachments didn't worked.
Sending the Code for 2 Programs......


*********GetDrives Program Begins Here******************
;This Program searches for all Drives located on your System.
OutFile "MyGetDrives.exe"

Function GetDrives
!define GetDrives `!insertmacro GetDrives`

!macro GetDrives _DRV _FUNC
Push $0
Push `${_DRV}`
GetFunctionAddress $0 `${_FUNC}`
Push `$0`
Call GetDrives
Pop $0
!macroend

Exch $1
Exch
Exch $0
Exch
Push $2
Push $3
Push $4
Push $5
Push $8
Push $9

System::Alloc 1024
Pop $2

StrCmp $0 '' 0 typeset
StrCpy $0 ALL
goto drivestring

typeset:
StrCpy $5 -1
IntOp $5 $5 + 1
StrCpy $8 $0 1 $5
StrCmp $8$0 '' enumex
StrCmp $8 '' +2
StrCmp $8 '+' 0 -4
StrCpy $8 $0 $5
IntOp $5 $5 + 1
StrCpy $0 $0 '' $5

StrCmp $8 'FDD' 0 +3
StrCpy $5 2
goto drivestring
StrCmp $8 'HDD' 0 +3
StrCpy $5 3
goto drivestring
StrCmp $8 'NET' 0 +3
StrCpy $5 4
goto drivestring
StrCmp $8 'CDROM' 0 +3
StrCpy $5 5
goto drivestring
StrCmp $8 'RAM' 0 typeset
StrCpy $5 6

drivestring:
System::Call 'kernel32::GetLogicalDriveStringsA(i,i) i(1024,r2)'

enumok:
System::Call 'kernel32::lstrlenA(t) i(i r2) .r3'
StrCmp $3$0 '0ALL' enumex
StrCmp $3 0 typeset
System::Call 'kernel32::GetDriveTypeA(t) i (i r2) .r4'

StrCmp $0 ALL +2
StrCmp $4 $5 letter enumnext
StrCmp $4 2 0 +3
StrCpy $8 FDD
goto letter
StrCmp $4 3 0 +3
StrCpy $8 HDD
goto letter
StrCmp $4 4 0 +3
StrCpy $8 NET
goto letter
StrCmp $4 5 0 +3
StrCpy $8 CDROM
goto letter
StrCmp $4 6 0 enumex
StrCpy $8 RAM

letter:
System::Call '*$2(&t1024 .r9)'

Push $0
Push $1
Push $2
Push $3
Push $4
Push $5
Push $8
Call $1
Pop $9
Pop $8
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
StrCmp $9 'Stop' enumex

enumnext:
IntOp $2 $2 + $3
IntOp $2 $2 + 1
goto enumok

enumex:
System::Free $2

Pop $9
Pop $8
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd

Section "GetDrivesSection"
${GetDrives} "HDD" "GetDrivesExample1"
SectionEnd

Function GetDrivesExample1
;MessageBox MB_OK "$9 ($8 Drive)"
MessageBox MB_OK "$9"
Push $0
FunctionEnd
**************GetDrives Program Ends Here*************


**************SearchFile Program Begins Here*********
; Feel free to change FileName and DriveName.
OutFile "MySearchFileExample.exe"

Section "OK"
Push "startup.bat"
Push "C:\"
Push $0
GetFunctionAddress $0 "MyFunction"
Exch $0
Push "1"
Push "1"
MessageBox MB_OK "Click OK to search for 'startup.bat' in C:\"
Call SearchFile
SectionEnd

Function SearchFile

Exch 4
Exch
Exch 3
Exch $R0 ; directory in which to search
Exch 4
Exch
Exch $R1 ; file or folder name to search in
Exch 3
Exch 2
Exch $R2
Exch 2
Exch $R3
Exch
Push $R4
Exch
Push $R5
Exch
Push $R6
Exch
Exch $R7 ;search folders with "."

StrCpy $R5 $R2 ;$R5 = custom function name
StrCpy $R6 $R3 ;$R6 = include subfolders

StrCpy $R2 ""
StrCpy $R3 ""

# Remove \ from end (if any) from the file name or folder name to search
StrCpy $R2 $R1 1 -1
StrCmp $R2 \ 0 +2
StrCpy $R1 $R1 -1

# Detect if the search path have backslash to add the backslash
StrCpy $R2 $R0 1 -1
StrCmp $R2 \ +2
StrCpy $R0 "$R0\"

# File (or Folder) Search
##############

# Get first file or folder name

FindFirst $R2 $R3 "$R0$R1"

FindNextFile:

# This loop, search for files or folders with the same conditions.

StrCmp $R3 "" NoFiles
StrCpy $R4 "$R0$R3"

# Preparing variables for the Callback function

Push $R7
Push $R6
Push $R5
Push $R4
Push $R3
Push $R2
Push $R1
Push $R0

# Call the Callback function

Call $R5

# Returning variables

Push $R8
Exch
Pop $R8

Exch
Pop $R0
Exch
Pop $R1
Exch
Pop $R2
Exch
Pop $R3
Exch
Pop $R4
Exch
Pop $R5
Exch
Pop $R6
Exch
Pop $R7

StrCmp $R8 "Stop" 0 +3
Pop $R8
Goto Done

Pop $R8

# Detect if have another file

FindNext $R2 $R3
Goto FindNextFile ;and loop!

# If don't have any more files or folders with the condictions

NoFiles:

FindClose $R2

# Search in Subfolders
#############

# If you don't want to search in subfolders...

StrCmp $R6 0 NoSubfolders 0

# SEARCH FOLDERS WITH DOT

# Find the first folder with dot

StrCmp $R7 1 0 EndWithDot

FindFirst $R2 $R3 "$R0*.*"
StrCmp $R3 "" NoSubfolders
StrCmp $R3 "." FindNextSubfolderWithDot 0
StrCmp $R3 ".." FindNextSubfolderWithDot 0
IfFileExists "$R0$R3\*.*" RecallingOfFunction 0

# Now, detect the next folder with dot

FindNextSubfolderWithDot:

FindNext $R2 $R3
StrCmp $R3 "" NoSubfolders
StrCmp $R3 "." FindNextSubfolder 0
StrCmp $R3 ".." FindNextSubfolder 0
IfFileExists "$R0$R3\*.*" RecallingOfFunction FindNextSubfolderWithDot

EndWithDot:

# SEARCH FOLDERS WITHOUT DOT

# Skip ., and .. (C:\ don't have .., so have to detect if is :\)

FindFirst $R2 $R3 "$R0*."

Push $R6

StrCpy $R6 $R0 "" 1
StrCmp $R6 ":\" +2

FindNext $R2 $R3

Pop $R6

# Now detect the "really" subfolders, and loop

FindNextSubfolder:

FindNext $R2 $R3
StrCmp $R3 "" NoSubfolders
IfFileExists "$R0$R3\" FindNextSubfolder

# Now Recall the function (making a LOOP)!

RecallingOfFunction:

Push $R1
Push "$R0$R3\"
Push "$R5"
Push "$R6"
Push "$R7"
Call SearchFile

# Now, find the next Subfolder

Goto FindNextSubfolder

# If don't exist more subfolders...

NoSubfolders:

FindClose $R2

# Returning Values to User

Done:

Pop $R7
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0

FunctionEnd

Function MyFunction
MessageBox MB_OK "startup.bat found at: $R0"

Push "Stop"
FunctionEnd

******************SearchFile Program Ends Here*********


Subject was already discussed
http://forums.winamp.com/showthread....hreadid=203599


Algorithm of this script (Locate + GetDrives):

1. Modern UI custom page
2. Start search button
3. Find specified file or file mask in all drives
4. Banner shows search in directory
5. Add founded files in List Box.
6. You must select one to enable Next button
7. If file deleted (since it found) then:
-Next button - disable
-Not existed file will deleted from List Box

Script used header