how to search for a particular file in MyComputer

R

ravindar thati

hello friends,

i am using ms access 2003.
i have a form with a button on it.
when i click that button, i want to display the full path of a
particular file in the hard disk i.e in MyComputer(which includes all
drives, c, d e.....).
if the search couldnt find that file, it should give a message that
the file is not found.


i have this code.


Private Declare Function OpenProcess Lib "kernel32" (ByVal
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal
dwProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal
hHandle As Long, ByVal dwMilliseconds As Long) As Long


Public Sub ShellAndWait(ByVal strCommand As String, Optional ExecMode
As VbAppWinStyle = vbMinimizedNoFocus)
On Error GoTo ProcedureError
Const kstrProcedureName = "ShellAndWait"


Dim ProcessID As Long
Dim hProcess As Long
Dim hWnd As Long
Dim ret As Long


'start the process
ProcessID = Shell(strCommand, CLng(ExecMode))


'wait for the process to finish
hProcess = OpenProcess(&H100000, False, ProcessID)
ret = WaitForSingleObject(hProcess, -1&)


'close the process handle
CloseHandle hProcess


ProcedureExit:
On Error Resume Next
Exit Sub


ProcedureError:
'need to re-raise the error to the calling procedure in the
appropriate format
Select Case Err.Number
Case Else 'exception raised in code
Err.Raise Err.Number, Err.Source, Err.Description
End Select
Resume ProcedureExit
Resume


End Sub


Private Sub Command1_Click()


Dim Results As String, ff As Long, FindFile As String


FindFile = "command.com"


ChDrive "c"
ChDir "c:\"
Command1.Enabled = False
Command1.Caption = "Searching..."
ShellAndWait "cmd /c dir /s /b /d /x " & FindFile & " > c:
\dir.out", vbHide
Command1.Caption = "Search"
Command1.Enabled = True


ff = FreeFile
Open "c:\dir.out" For Binary As #ff
Results = String(LOF(ff), Chr(0))
Get #ff, , Results
Close #ff


MsgBox Results


End Sub


but the problem is here.
this code searches for a file in a particular drive.
but i want to perform a complete hard drive search for locating any
file.
what changes should i do in that code.
or any body else please give me any piece of code to accomplish my
task.
thanq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top