Selecting a file by its location rather than its name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • woolls01
    New Member
    • Jan 2008
    • 9

    Selecting a file by its location rather than its name

    I have a listbox and would like to use it to select a file from a known location, but I want to select by position as its name may change (example: if someone selects the first option in listbox then the first file within the folder d:\workpack is selected).

    Thanks
  • daniel aristidou
    Contributor
    • Aug 2007
    • 494

    #2
    Originally posted by woolls01
    I have a listbox and would like to use it to select a file from a known location, but I want to select by position as its name may change (example: if someone selects the first option in listbox then the first file within the folder d:\workpack is selected).

    Thanks
    Is the file the only file in the folder......ie location or is there a group of files in the known location

    Comment

    • woolls01
      New Member
      • Jan 2008
      • 9

      #3
      There are about 8 files in the subfolder and there 'll always be the same number of options in the listbox

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I think you'll find that most if not all methods of finding the file will return them in alphabetical order by file name. So the idea of "position" may not be meaningful.

        But if you're ok with that, then it's pretty simple. Just start picking through the files in the folder, and stop when you get to the 'nth' one.

        Comment

        • woolls01
          New Member
          • Jan 2008
          • 9

          #5
          Yes but what code do i need to select the nth file?

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            It might depend a bit on what version of VB you're using. But in any case, look up "FileSystemObje ct model" in the documentation. This will explain how to use FSO to go through the files in a folder.

            Comment

            Working...