Results 1 to 7 of 7

Thread: Auto find Files in Directory

  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 Auto find Files in Directory

    I would like to have this program see any file (.lyr) in a directory and list it...
    Right now I need to enter the file name into my program in order for the program to find it
    Here is how I have it now...

    Code:
    Private Sub MultiPage1_Change()
    'This is where you list the file you want to use for the layers
    lstDat.Clear
    ListlayerName.Clear
    ListLayerColor.Clear
    ListLayerStyle.Clear
    
    
        Select Case MultiPage1.SelectedItem.Caption
            Case " A"
                lblDiscipline.Caption = "Architectural"
                
                If MultiPage1.Arch.LstCata.ListCount = 0 Then
                    MultiPage1.Arch.LstCata.AddItem "A-Gen-Layer"
                    MultiPage1.Arch.LstCata.AddItem "A-Clg-Layer"
                    MultiPage1.Arch.LstCata.AddItem "A-DorWin-Layer"
                    MultiPage1.Arch.LstCata.AddItem "A-Floor-Layer"
                    MultiPage1.Arch.LstCata.AddItem "A-Wall-Layer"
                    MultiPage1.Arch.LstCata.AddItem "A-Site-Layer"
                    MultiPage1.Arch.LstCata.AddItem "A-Roof-Layer"
                    MultiPage1.Arch.LstCata.AddItem "A-Circ-Layer"
                End If
                                
            Case " C"
                lblDiscipline.Caption = "Civil"
                
                If MultiPage1.Civil.lstCatc.ListCount = 0 Then
                    MultiPage1.Civil.lstCatc.AddItem "C-Site-Layer"
                    MultiPage1.Civil.lstCatc.AddItem "C-Grading-Pave"
                    MultiPage1.Civil.lstCatc.AddItem "C-Uity-Layer"
                    MultiPage1.Civil.lstCatc.AddItem "C-Sheet-File-Names"
                    MultiPage1.Civil.lstCatc.AddItem "C-Model-File-Names"
                End If
                                
            Case " E"
                lblDiscipline.Caption = "Electrical"
                
                If MultiPage1.Elect.lstCate.ListCount = 0 Then
                    MultiPage1.Elect.lstCate.AddItem "E-Light-Layer"
                    MultiPage1.Elect.lstCate.AddItem "E-Power-Layer"
                    MultiPage1.Elect.lstCate.AddItem "E-Misc-Layer"
                End If
                                
            Case " M"
                lblDiscipline.Caption = "Mechanical"
                
                If MultiPage1.Mech.lstCatm.ListCount = 0 Then
                    MultiPage1.Mech.lstCatm.AddItem "M-HVAC-Layer-1"
                    MultiPage1.Mech.lstCatm.AddItem "M-HVAC-Layer-2"
                    MultiPage1.Mech.lstCatm.AddItem "M-HVAC-Layer-3"
                    MultiPage1.Mech.lstCatm.AddItem "M-HVAC-Layer-4"
                    MultiPage1.Mech.lstCatm.AddItem "M-Plum-Layer"
                    MultiPage1.Mech.lstCatm.AddItem "M-Fire-Layer"
                End If
                
            Case " S"
                lblDiscipline.Caption = "Structural"
                
                If MultiPage1.Struct.lstCats.ListCount = 0 Then
                    MultiPage1.Struct.lstCats.AddItem "S-Layer-List-1"
                    MultiPage1.Struct.lstCats.AddItem "S-Layer-List-2"
                    MultiPage1.Struct.lstCats.AddItem "S-Layer-List-3"
                    MultiPage1.Struct.lstCats.AddItem "S-Layer-List-4"
                End If
                            
            Case " G"
                lblDiscipline.Caption = "General"
     
                If MultiPage1.General.lstcatg.ListCount = 0 Then
                    MultiPage1.General.lstcatg.AddItem "G-General-Text"
                    MultiPage1.General.lstcatg.AddItem "G-Border-Layer"
                    MultiPage1.General.lstcatg.AddItem "G-Elev-Layer"
                    MultiPage1.General.lstcatg.AddItem "G-Sec-Layer"
                    MultiPage1.General.lstcatg.AddItem "G-Schd-Layer"
                    MultiPage1.General.lstcatg.AddItem "G-Detail-Layer"
                 End If
      
        
                
            End Select
    
    
    End Sub
    This is only my thrid problem I have written in VBA...

    Thanks
    Attached Images Attached Images

  2. #2
    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

    Smile Re: Auto find Files in Directory

    Let me see if I can put this in another way:

    I would like to be able to populate a field with a certain type of file (.lyr) in a certain directory. (…/VBA)

    I now need to include the files I created in the VBA program but I would like the program to find and enter these files by itself.

    Can anyone get me start by maybe giving me some ideas where to start…???

    If it can't done that's fine. The program works great but I just want to make it better by making it easier for the Cad Managers to work with...

    Thanks
    Last edited by CadDog; 2006-08-01 at 05:31 PM.

  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

    Wink Re: Auto find Files in Directory

    In doing a little read, while waiting, I have come across this:

    Tools >> References >> MicroSoft Scripting RunTime...

    I think this is what I'm looking for...

    Only Time will Tell...

    Keep your fingers cross for me...

    More news later...

    Thanks for stopping by my little thread...

  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: Auto find Files in Directory

    Is the DIR function insufficient?
    C:> ED WORKING....


    LinkedIn

  5. #5
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Auto find Files in Directory

    Quote Originally Posted by CadDog
    I would like to have this program see any file (.lyr) in a directory and list it...
    You may need to explore the "Scripting.filesystemobject" in detail. It is very powerful and packed with all the file handling tools.

    Here is a sample from AutoCAD VBA Help file:




    Code:
    'Searches a folder for files
    Sub ShowFolderList(folderspec)
    Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    Set fc = f.Files
    For Each f1 In fc
    'You can check the file type or compare if the last four
    'characters are ".lyr"
    s = f1.Type
    'Then you can open it for read/write/append. See the sample code
    Next
    End Sub
     
    'Opens text file for reading/writing
    Sub TextStreamTest()
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    Dim fs, f, ts, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.CreateTextFile "test1.txt"
    'Create a file
    Set f = fs.GetFile("test1.txt")
    Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
    ts.Write "Hello World"
    ts.Close
    Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
    s = ts.ReadLine
    MsgBox s
    ts.Close
    End Sub
    Hope this will help you.

    Regards,
    Abdul Huck

  6. #6
    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: Auto find Files in Directory

    I will need to get back to it in a while...

    Like some other around here, I need to get some work out in the next few weeks...
    (Where have all the Civil Engineers Gone...???)

    I want to tell you that I will not be doing much with the code until then...
    I didn't want anyone to think that I have given up or not taking notes...
    I welcome all and any inputs and thank you two for having something to add...

    I did look at DIM but it may be limited in some ways...

    Abdul, I will take a good hard look at the bit of code you gave me...

    Again, Guys I sorry but I need to paid those bills first and play later...

    DTW: I told a few of the cadd manager what I was planning on doing and
    like always a few got concern and worry that I was go to change it at all...
    Once I talked to them and told them that it would be a while and
    that I will create a second code and once the bugs are gone (if there is any)
    then and only then will I replace the old with the new...

    Control of ideas...
    It haven't ever stop me before...


    Here is one of my first Lisp/DCL code I wrote about 9 years ago for AutoCAD 12...
    And they said it couldn't be done...
    Attached Images Attached Images

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

    Default Re: Auto find Files in Directory

    Quote Originally Posted by CadDog
    And they said it couldn't be done...
    ...what couldn't be done? ...getting the engineers to change?
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. Replies: 14
    Last Post: 2019-01-02, 07:41 PM
  2. Search current directory for CTB/STB files
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 5
    Last Post: 2016-10-25, 04:28 PM
  3. 2014: Revit TMP files in my local temp directory. What are those?
    By Silleke in forum Revit - Platform
    Replies: 2
    Last Post: 2015-04-13, 07:33 PM
  4. Enter Directory For Temp. Files Message
    By zane.rettstatt in forum AutoCAD General
    Replies: 2
    Last Post: 2007-08-08, 01:28 PM
  5. Replies: 17
    Last Post: 2006-09-09, 02:01 AM

Posting Permissions

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