Welcome !

 File Search from Two Folders

Author Message

  • Total Posts : 8
  • Scores: 0
  • Reward points : 0
  • Joined: 2/29/2016
  • Status: offline
File Search from Two Folders Thursday, December 01, 2016 8:30 AM (permalink)
Hopefully I can explain this clearly enough...
I have a program (below) that searches file names from two different folder and opens them up simulataneously.
In Folder 1, the file names are like this 1998M730001 (only the 1st 7 characters are important in this folder) or L592530001 (Only the first 6 characters are important in these files that begin with L)
In the Folder 2, the file name are like this: 1998M73G001 (note the additional G) or L59253G001. In this folder, all characters are significant. 
(Some of the file names begin with an "L" and down at the bottom of the code, there is a function that says to only search out to 6 digits for those that begin with L and 7 digits for those that don't start with L)
Here is what i want it to do: In some cases, there are similar names like 1998M73G002 in Folder 2 and right now the code is only searching out to 6 digits for some and 7 digits for the other. I would like it to stay that way for the Folder 1 search but for the Folder 2 search(highlighted below), I would like to search out to 11 digits for files that don't start with L and 10 digits for those that do start with L.
Thank you for any help and let me know if you have any questions.
Dim strSearchFileName, strFolderName1, strFolderName2, strFile1, strFile2
 strSearchFileName = getSearchFile()
 If strSearchFileName = "" Then WScript.quit()
 strFolderName1 = "K:\08 Admin Support\02 Develop & Control Docs & Data\09 Industry Docs\Customer Standards\GEAE\GE Drawings"
 strFolderName2 = "K:\08 Admin Support\02 Develop & Control Docs & Data\17 Final Inspection Tech Cards"

 'Get file if folder and file exists (Returns String)
 strFile1 = getFile(strFolderName1, strSearchFileName)
 strFile2 = getFile(strFolderName2, strSearchFileName) [/style]
 'If _strFile1 and _strFile2 are not equal to nothing open the files
 If strFile1 <> "" And strFile2 <> "" Then
                 MsgBox("A drawing containing '" & strSearchFileName & "' was not found in GEAE.")
 End If
 'Get file if folder and file exists (Returns String)
 Private Function getFile(strFolderName, strFileName)
                 Dim objFSO, folder, file
                 Set objFSO = CreateObject("Scripting.FileSystemObject")
'Verify passing folder exists
                 If objFSO.FolderExists(strFolderName) Then     
                                 Set folder = objFSO.GetFolder(strFolderName)
                                 'Loop over all files in the folder until the searchFileName is found
                                 For each file In folder.Files
                                                 If InStr(file.Name, strFileName) >=1  Then
                                                                 getFile = file.path
                                                                 Exit Function
                                                 End If
                 End If
                 getFile = ""
 End Function
 'Get user input (Returns String)
 Private Function getSearchFile()
                 getSearchFile = InputBox("Find a Part Number containing:" & vbCr & vbCr & "(Case Sensitive)" & vbCr & vbCr & "Examples: L59253 or 1967M33")

                If Left(getSearchFile,1) = "L" Then
                        getSearchFile = Left(getSearchFile,6)
                        getSearchFile = Left(getSearchFile,7)
                End If
End Function
 'Opens File
 Private Sub openFile(strPath) 
                 CreateObject("WScript.Shell").Run chr(34) & strPath & chr(34) 
 End Sub
    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2017 ASPPlayground.NET Forum Version 3.9