FileSystemObject.FindFile? Script?

I want to create a simple VBS Script that will find a File that I know is in the drive (but do not know exactly where) and put it in the C:\TempFolder, for example, a "wishful thinking" script would be:
Dim fileword
Set fileword=CreateObject("Scripting.FileSystemObject")

fileword.FINDFILE ("winword.exe")

fileword.MoveFile "From whereever it is - WINWORD.EXE", "c:\TempFolder\"  
Of course the program won't work, but with that in mind maybe someone can help me re-script.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Recursive search to find a file. It will recursively search thorughut your drive. You can implement this to searchtrough many drives...

Option Explicit

Dim fso  'Scripting.FileSystemObject
Dim theFolder  'Scripting.Folder
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFolder = fso.GetFolder("C:\")
Dim theResult
theResult = searchIt(theFolder, "winword.exe")
MsgBox theResult
Set theFolder = Nothing
Set fso = Nothing
End Sub

Private Function searchIt(theStartPath, TheFileName)
   Dim localF  'Scripting.File
   Dim subDir 'Scripting.Folder
   On Error Resume Next
   For Each localF In theStartPath.Files
      If LCase(localF.Name) = LCase(TheFileName) Then
         If Err.Number = 0 Then
            searchIt = localF.Path
            Exit Function
          End If
      End If
   For Each subDir In theStartPath.SubFolders
      searchIt = searchIt(subDir, TheFileName)
      If searchIt <> "" Then
         Exit Function
      End If
End Function


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi, sorry to sort of repeat the same thing, but the previous suggestion was submitted while I was working on my post. Anyway, here goes:

Call folderlist("C:\", "winword.exe", "C:\TempFolder")

sub folderlist(searchFolder,toFind, destDir)

     On Error Resume Next
     Set fso = CreateObject("Scripting.FileSystemObject")

     Dim myFolder,Subfolder,mySubfolders, File, tmpFileName

     If (Right(searchFolder,1) <> "\") Then
          searchFolder = searchFolder & "\"
        End If

     Set myFolder = fso.GetFolder(searchFolder)
     Set mySubFolders = myFolder.SubFolders

        For each File in MyFolder.Files   'Loop trough the files in the folder
          'WScript.Echo ("File: '" & File.Name & "'")
          toFind = LCase(toFind)
          tmpFileName = LCase(File.Name)
          if (tmpFileName = toFind) then

             WScript.Echo (Left(file.path, Len(file.path) - Len( )   )
             WScript.Echo (File.Size & " bytes" & vbtab & File.Type & vbtab & File.DateCreated & vbtab & )

             If (Right(destDir,1) <> "\") Then
               destDir = destDir & "\"
             End If

             if fso.FileExists(destDir & Then
               WScript.Echo destDir & & " already exists."
               WScript.Echo ("fso.CopyFile " & File.path & ", " & destDir)
               fso.CopyFile File.path, destDir
             End If

             If (Err.Number <> 0) Then
               WScript.Echo ("Error: " & Err.Number & vbcrlf & Err.Description & vbcrlf & Err.Source)
             End if
          End If

     For each Subfolder in myFolder.SubFolders

          'WScript.Echo ("Subfolder: " & Subfolder.Name)
          Call folderlist(Subfolder.path, toFind, destDir)
end sub
Here's a slightly different take, relying on the Windows Dir command as opposed to recursion. Performance benefit should be significant.

[End of 20-point answer]

Copy-and-paste the following into a vbs file, and execute. FindFile parameters are:

strFind - Name of the file to find. Wildcards can be used.
strDest - Location to copy files to.
StartIn - Location to start search in. Pass an empty string to have Sub search all local drives.


Call FindFile("winword.exe", "C:\Temp\","C:\Temp")

Sub FindFile(strFind, ByVal strDest, StartIn)

Dim fso, ts
Dim sh

Const TemporaryFolder = 2

Dim fldrTemp
Dim strBat, strLog

Set fso = CreateObject("Scripting.FileSystemObject")

With fso

'   Verify Destination and Starting (if applicable) folders exist.
    If Not .FolderExists(strDest) Then
        Wscript.Echo "Destination folder does not exist."
     Set fso = Nothing
     Exit Sub
    ElseIf Not StartIn = Empty And Not .FolderExists(StartIn) Then
        Wscript.Echo "Starting folder does not exist."
     Set fso = Nothing
     Exit Sub
    End If
    strDest = .GetFolder(strDest).Path

'   Create temporary file names.
    fldrTemp = .GetSpecialFolder(TemporaryFolder).Path & "\"
    strBat = fldrTemp & "_FindFile.bat"
    strLog = fldrTemp & "_FindFile.log"
'   Create batch file.
    Set ts = fso.CreateTextFile(strBat, True)
    If .FileExists(strLog) Then .DeleteFile strLog, True
    If StartIn = Empty Then
     Dim drv
        For Each drv In .Drives
            If drv.DriveType = Fixed Then
                cmd = "dir """ & drv & "\" & strFind & """ /b /s >> " & strLog
                ts.WriteLine cmd
            End If
        cmd = "dir """ & .GetFolder(StartIn).Path & "\" & strFind & """ /b /s >> " & 

        ts.WriteLine cmd
    End If
'   Execute batch file.

    set sh = CreateObject("WScript.Shell")
    sh.Run strBat, 7, True
    .DeleteFile strBat, True
'   Process results. Copy file(s) to new Destination folder.
    Set ts = .OpenTextFile(strLog)
    If ts.AtEndOfStream Then
     Wscript.Echo "No files found!"
    End If
    Dim myFile, intButton
    Do Until ts.AtEndOfStream
     myFile = ts.ReadLine
     If .FileExists(strDest & "\" & .GetFile(myFile).Name) Then
         intButton = sh.Popup("File exists in destination folder.

     Else: intButton = 6 ' Yes
     End If
        If intButton = 6 Then .CopyFile myFile, .GetFolder(strDest) & "\"
    .DeleteFile strLog, True
End With

Set sh = Nothing
Set fso = Nothing: Set ts = Nothing: Set drv = Nothing

End Sub
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Add the following line to the Sub Declarations section.

Const Fixed = 2
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Moderator, my recommended disposition is:

    Accept Cimperiali's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.