Results 1 to 10 of 10

Thread: Filesystemobject and VB6

  1. #1

    Thread Starter
    Registered User
    Join Date
    Mar 2016
    Posts
    6

    Filesystemobject and VB6

    Hello and thanks to any one who responds

    I really struggle with the Filesystemobject

    I have a portable drive that has the files I use for a programme in a folder I use a lot.

    I sometimes run this programme on my desktop, laptop, or in any other place I might be.

    So, when I connect this portable drive, its Drive letter is always different (and unknown to me).

    What I need, please, is code to loop through each drive, then through each folder in that drive, till it locates my particular folder - then I can retrieve and save files to that folder

    Thanks again
    edenhope

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: Filesystemobject and VB6

    Have you looked at the DriveListBox component? It will recognize the portable drive if you run it after plugging it in.

    Edit: Then you can use the DirListBox and FileListBox to 'search for' your file(s).

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Filesystemobject and VB6

    If you are running the program from this drive why not use App.Path ?

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: Filesystemobject and VB6

    I think OP is not running from that drive, but is accessing that drive to find saved files in a directory.

    OP---here is a very simple way of using the DriveListBox and DirListBox to search for a directory. (Then, of course, if desired, you can use the FileListBox to display files in the found directory.

    I put a textbox with its text being the Folder (Directory) I want to find (located on the external drive). I run the program, select the drive letter of the external drive, and then click on the command button to find the path to that folder. This should be easy for you to then modify it so you can do whatever you want once the folder is found.

    Code:
    Private Sub Command1_Click()
       Dim x As Integer
       For x = 0 To Dir1.ListCount - 1
        Dir1.ListIndex = x
        If UCase(Dir1.List(x)) = UCase(Drive1.Drive) & "\" & UCase(Text1.Text) Then
            MsgBox "We have found this drive, " & Dir1.List(x)
        End If
       Next x
    End Sub
    Private Sub Drive1_Change()
        Dir1.Path = Drive1.Drive
    End Sub

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Filesystemobject and VB6

    I suggest you avoid naming your folders things like System32.

    This entire enterprise seems dicey if not doomed. Why not just add a "browse for folder" dialog so the user can navigate to the desired location?

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: Filesystemobject and VB6

    good point...BUT....if the program can be set up to browse only for the drive letter (only necessary interaction for the user), and any recursiveness is needed, would be quicker than using dialogbox to drill down. Yes?

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Filesystemobject and VB6

    I get the idea that the OP wants an "auto-magician" to just find the folder. Of course if the path is fixed and known to the code than it could just iterate through the list of drives checking each one for the path being present. No need for any time consuming drive scanning.

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Filesystemobject and VB6

    IMO I would think using an INI file and a browse method would be the way to go.
    In most cases the removable drive will get the same drive letter it got before on that PC so if that were to be stored in an INI file then when the program starts it could look there for the files and if not there then trigger a browse to let the user locate the file or folder as needed.

  9. #9
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: Filesystemobject and VB6

    correct...my thoughts exactly, "if the path is fixed". (And it probably is). If not, then some sort of drive scanning would be needed, searching subfolders, etc. Anyway....I like your idea of the dialogbox...leaves no doubt. May take a few more seconds, but makes coding a lot easier.

    OUTA HERE!

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Filesystemobject and VB6

    One other thing to consider is when you try to scan all the drives and folders to locate your files you run into the possible issue that the user made a backup copy and your program locates that rather than the correct location and the can of worms is opened.

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