Results 1 to 5 of 5

Thread: Search harddisk for a file

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    10
    I think I have searched the entire web for a code that searches my computer for a file i for example put in a textbox.
    Could anyone please give me such a code?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Filename or files with the text contained in files?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    code

    'does file exist using fso

    Dim sFile$

    sFile = "Name And Path Of Your File"

    Dim fs As Object
    Set fs = CreateObject("Scripting.FileSystemObject")

    If fs.fileexists(sFile$) = True Then
    MsgBox "File Exists...Your code here!"
    Else
    MsgBox "Does Not Exist...Your code here!"
    End If
    Set fs = Nothing


    Enjoy

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Or if you want to search the hard drive for a file.

    Code:
    Option Explicit
    Option Compare Text
    
    Dim fso
    Dim blFound As Boolean
    
    Private Sub Command2_Click()
        Dim myFolder
        
        'create a file scripting object
        Set fso = CreateObject("Scripting.FileSystemObject")
        
        Me.Caption = "Working!"
        
        'the folder to start looking in
        myFolder = "c:\"
        searchFileNames fso.getfolder(myFolder).Files, Text1.Text
        searchFolderNames fso.getfolder(myFolder).subfolders, Text1.Text
        
        blFound = False
        Me.Caption = "DONE!"
        
    End Sub
    
    
    Private Sub searchFolderNames(myFolderList, strFile As String)
        Dim myFolder
        
        For Each myFolder In myFolderList
          If blFound = True Then Exit Sub
          
          'search the files for this folder
          searchFileNames fso.getfolder(myFolder).Files, strFile
          
          If myFolder.Name = strFile Then
            MsgBox "Folder Found at  : " & myFolder.Path
            blFound = True
            Exit Sub
          End If
          
          'recursivley search the folders
          searchFolderNames fso.getfolder(myFolder).subfolders, strFile
        Next
    
    End Sub
    
    Private Sub searchFileNames(myFolder, strFile As String)
        Dim MyFile
        
        For Each MyFile In myFolder
          If MyFile.Name = strFile Then
            MsgBox "File Found at  : " & MyFile.Path
            blFound = True
            Exit Sub
          End If
        Next
        
    End Sub
    Hope it helps.
    Iain, thats with an i by the way!

  5. #5
    Guest
    Or you can use the FindFirstFile API.

    Code:
    Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width