Results 1 to 4 of 4

Thread: Directory Listbox Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Directory Listbox Question

    This should be an easy one. What I want to do is on the
    Dir1 click event I want to create a text file. This I can do. However, want the created file to be named after the folder that was clicked in the Dir1. So Say I click the "ROCK" folder, I want a textfile to be created that is called "Rock.txt". The trouble I'm having is it just creates a folder named "dir1.txt" no matter what folder is clicked. I hope this makes sense. So I guess I don't really want the textfile named: Dir1.name

    Is there a way to create a file based on the name of the selected folder in the Directory Listbox? Any help is appreciated.

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    The following code will give you the proper filename:
    Code:
    Private Sub File1_Click()
      Dim sFileName As String
      sFileName = File1.List(File1.ListIndex)
      sFileName = Left(sFileName, InStr(sFileName, ".") - 1) & ".txt"
    End Sub
    Sometimes what you're looking for is exactly where you left it.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Maybe I'm wrong but....

    What I'm wanting to do is Name the file after the FOLDER that is clicked in the directory listbox, not the name of the file in the filelistbox.

  4. #4
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    Sorry, try this:
    Code:
    Private Sub Dir1_Click()
      Dim sDirName As String
      sDirName = Dir1.List(Dir1.ListIndex)
      sDirName = Right(sDirName, Len(sDirName) - InStrRev(sDirName, "\")) & ".txt"
    End Sub
    Sometimes what you're looking for is exactly where you left it.

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