Results 1 to 7 of 7

Thread: I don't have a CLUE...

  1. #1
    I could stop if I wanted to CadDog's Avatar
    Join Date
    2005-06
    Location
    So Ca
    Posts
    439
    Login to Give a bone
    0

    Default I don't have a CLUE...

    Hi everyone,

    I have search the net, this site and even asked around
    to see if I can understand how to start a small program I need...

    The Layout:

    I want to submit a list drawing names to window exploder using excel or word
    and then build a list back into excel or word showing drawing (system path) locations.

    Here is what I have been told:
    "You’ll need to reference the File System Object and
    use a Recursive Function to loop (search) through your folders to find the files."
    OK, I know my lisp but I'm have only create few VBA programs a while back
    and I have no clue in how to begin this program...

    Basically, what I want to do again (in other words):

    Create (and/or given) a list of drawings names...
    Search my system and locate the drawings...
    Lastly, list down their path locations within our system...

    Currectly, I do this one at a time and it's really taking me a long time to do...

    Any and all help is welcome...

    Thanks before hand to all who read this thread...

    *****
    BTW: If there is a better location for this question to be posted please place it there.
    This being a basically VBA question I thought this was the best place for me to ask...

    Thanks again

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: I don't have a CLUE...

    First, if you are simply searching your filesystem, how can you be sure that there aren't duplicate file names and that you won't find the wrong file? Unless you make some assumptions, you would need to restrict the search or have some path info to start with.
    C:> ED WORKING....


    LinkedIn

  3. #3
    I could stop if I wanted to CadDog's Avatar
    Join Date
    2005-06
    Location
    So Ca
    Posts
    439
    Login to Give a bone
    0

    Default Re: I don't have a CLUE...

    Thanks ED...

    All our drawing have unique drawing name with job numbers...

    For example:

    6008956C201R2.dwg

    But I would still put an if statement if not found...

    Sometimes the Revised drawings are placed in a unique folders apart from the project for many reasons however, they all still have unique numbers. That is our company standards.

    "No drawing is alike so no drawing will be name the same"

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: I don't have a CLUE...

    Somebody can still make a copy of the "unique" file name, but if you're just searching a project folder and not a whole drive, you limit your chances for errors to occur. That being the case, to do "recursion" you need to create a function that searches the objects only in one folder, passing a folder object as the argument. Examine the type of each object. If the type is a file, check the name and if its the one you are looking for, return the path. If the type is a folder, call the same function again using the subfolder as an argument.

    For code examples, you might try searching this forum for the FileSytemObject or looking in vba help. If I get time later I might be able to do something.
    C:> ED WORKING....


    LinkedIn

  5. #5
    I could stop if I wanted to CadDog's Avatar
    Join Date
    2005-06
    Location
    So Ca
    Posts
    439
    Login to Give a bone
    0

    Default Re: I don't have a CLUE...

    Thanks ED,

    I will check out this site again and see if I can find some close to what I need to begin the program.

    Thanks again...

    I'll post if I find any that I think can help me...

  6. #6
    Member
    Join Date
    2003-11
    Posts
    13
    Login to Give a bone
    0

    Default Re: I don't have a CLUE...

    Hi, You could try the "dir" VBA-command, there is a lot of documentation on that, the File System Object is more interesting, but is poorly documented. But if you only want to compare names, "dir" will do. In VB (not the A)-forums you will find many examples that are easy to implement in VBA. Build a list using a mask (company standard) or compare on the fly.

  7. #7
    Active Member
    Join Date
    2007-12
    Posts
    68
    Login to Give a bone
    0

    Default Re: I don't have a CLUE...

    Cheer up, what you're asking for can be quite a task. A "recursive" function is a function that calls -itself-. Its sorta like spelling the word "bananna" .. easy enuff to do, you just have to know when to -stop- ....

    You dont have to call the "File System Object", you can do it all from source code.

    included in this post is an entire *module* of code. Copy/paste it into a VBA code module. To do this, in VBA, click "Insert", then "Module". In the blank screen that appears, copy all the source code posted below.

    The module this code creates will search any folder you specify, for a file of a certain type ("*.dwg". "*.xls", etc) and will tunnel down through all the subfolders underneath.

    When it finds that type of file, it jumps down to the last routine, called "DoSomethingWithFile". here, you can put your own code to do something with the NAME of the file found. Right now, all it does is Debug.Print out the full path/filename of the file it finds. You can put your own code in here, and make this module do your bidding.
    Code:
    Private Const vbDot = 46
    Private Const MAX_PATH As Long = 260
    Private Const INVALID_HANDLE_VALUE = -1
    Private Const vbBackslash = "\"
    Private Const ALL_FILES = "*.*"
    
    Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
    End Type
    
    Private Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
    End Type
    
    Private Declare Function FindClose Lib "kernel32" _
        (ByVal hFindFile As Long) As Long
    
    Private Declare Function FindFirstFile Lib "kernel32" _
        Alias "FindFirstFileA" (ByVal lpFileName As String, _
        lpFindFileData As WIN32_FIND_DATA) As Long
    
    Private Declare Function FindNextFile Lib "kernel32" _
        Alias "FindNextFileA" (ByVal hFindFile As Long, _
        lpFindFileData As WIN32_FIND_DATA) As Long
    
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    Private Declare Function lstrlen Lib "kernel32" _
        Alias "lstrlenW" (ByVal lpString As Long) As Long
    
    Private Declare Function PathMatchSpec Lib "shlwapi" _
        Alias "PathMatchSpecW" (ByVal pszFileParam As Long, _
        ByVal pszSpec As Long) As Long
    
    
    Dim sFileExt As String
    Dim sFileRoot As String
    
    
    
    Public Sub FindAllFiles(FileType As String, StartPath As String)
        ' recursively searches a passed path for files of a given type
        ' returns a safearray of the fully qualified pathspecs
        ' FileType: a wildcard string of the file extension, ie; "*.dwg" or "*.xls"
        
        sFileRoot = QualifyPath(StartPath) 'start path
        sFileExt = FileType 'file type of interest
        
        Call SearchForFiles(sFileRoot)
    
    End Sub
    
    
    Private Sub SearchForFiles(sRoot As String)
    
        Dim WFD As WIN32_FIND_DATA
        Dim hFile As Long
        
        hFile = FindFirstFile(sRoot & ALL_FILES, WFD)
        
        If hFile <> INVALID_HANDLE_VALUE Then
            
            Do
            'if a folder, and recurse specified, call method again
            If (WFD.dwFileAttributes And vbDirectory) Then
                If Asc(WFD.cFileName) <> vbDot Then
                    SearchForFiles sRoot & TrimNull(WFD.cFileName) & vbBackslash
                End If
            Else
                'must be a file..
                If MatchSpec(WFD.cFileName, sFileExt) Then
                    DoSomethingWithFile sRoot & TrimNull(WFD.cFileName)
                End If 'If MatchSpec
            End If 'If WFD.dwFileAttributes
            
            Loop While FindNextFile(hFile, WFD)
        End If 'If hFile
        
        Call FindClose(hFile)
    
    End Sub
    
    
    Private Function QualifyPath(sPath As String) As String
        ' formats passed path string to be used in recursive API search
        If Right$(sPath, 1) <> vbBackslash Then
            QualifyPath = sPath & vbBackslash
        Else
            QualifyPath = sPath
        End If
    
    End Function
    
    
    Private Function TrimNull(startstr As String) As String
        ' trims NULL char (ascii 0) from strings returned by API calls
        TrimNull = Left$(startstr, lstrlen(StrPtr(startstr)))
    End Function
    
    
    Private Function MatchSpec(sFile As String, sSpec As String) As Boolean
        ' uses API version of the "LIKE" command
        MatchSpec = PathMatchSpec(StrPtr(sFile), StrPtr(sSpec))
    
    End Function
    
    
    Private Sub DoSomethingWithFile(FoundFileName As String)
        ' use this routine to do something with each file found
        ' we'll do nothing but print out the filename found
        Dim FoundName As String: FoundName = FoundFileName
        
        Debug.Print FoundName
    
    End Sub
    Last edited by Ed Jobe; 2008-03-17 at 03:49 PM. Reason: Added Code tags.

Similar Threads

  1. 2016: no clue why "structure is unstable"
    By narlee in forum Revit Structure - General
    Replies: 2
    Last Post: 2015-08-11, 08:23 PM
  2. 2015: No Clue!
    By baf484 in forum Revit - LT Support
    Replies: 2
    Last Post: 2014-12-28, 12:09 PM
  3. I have no clue
    By cadman6735 in forum Revit Architecture - General
    Replies: 5
    Last Post: 2008-11-13, 09:51 PM

Posting Permissions

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