Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Feb 2003
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filenames Retrieve (VB ver 6)

    Hi,

    How can I retrieve the required files (eg. TXT) from a particular folder in VB? The reason is to pick up these required text files and process. Thanks...

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Filenames Retrieve (VB ver 6)

    Search here for FileSystemObject, if you are okay with using the Scripting library, otherwise check your online help for Dir and Open.

  3. #3
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filenames Retrieve (VB ver 6)

    Here's an example of how to do this:

    Dim strTemp as String
    Dim f as Long
    Dim strData as String
    strTemp=Dir("C:MyFolder*.txt")
    Do until strTemp=""
    f=FreeFile
    Open "C:MyFolder" & strTemp For Binary Access Read As f
    strData=Space(LOF(f))
    Get f,,strData
    ProcessTextFileData strData
    Close f
    Kill "C:MyFolder" & strTemp
    strTemp=Dir
    Loop

    In my example above, ProcessTextFileData would be a function you write, with an string argument that this example would feed it. This example will run through every .txt file within the folder a folder on the C: drive root called 'MyFolder'. It also deletes the file once it is processed (the Kill statement), of course you may want your 'processing' function to return true or false as to whether it worked or not, before you delete the file.

    Hope this helps.

Posting Permissions

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