Results 1 to 4 of 4

Thread: Finding the highest number in a directory... STILL UNRESOLVED

  1. #1

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718

    Finding the highest number in a directory... STILL UNRESOLVED

    We are currently building a package which places each estimate number into a file like this...

    c:\estimates\1.txt
    c:\estimates\2.txt
    c:\estimates\3.txt
    etc.

    I have programmed a listview to read-in all the files in the estimates directory... but you have to give it a number from at to... IE.

    For Intx = 0 to 25000

    The question being... how can i search the directory for the highest number of file to that number can replace the 25000 in the example. The trouble is, when the user enters a number 25001... it won't find it.

    I can't set the number to 10000000 before anyone asks....as it would take weeks to open the program.

    Any help would be much appeciated.

    Regards,

    Paul.
    Last edited by VisionIT; Feb 6th, 2003 at 04:43 AM.

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Use DIR() and that will step through all files with the required name.
    Use the FSO, and obtain the .Count property.
    Save the last number used in the Registry / a file.
    Sort the directory and get the last number.

  3. #3

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    Any idea's on physical code M8... you lost me a bit there!

    Regards,

    Paul.

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    There are different approaches that you could use (some of which are shown above). Some are repeated here with more details:

    Use DIR() and step through all files with the required name.
    VB Code:
    1. SearchName = "C:\Estimates\*.TXT"
    2. f = Dir(SearchName, vbReadOnly)
    3. While f <> ""
    4.             MsgBox f
    5.             f = Dir()
    6. Wend

    Use the FSO, and obtain the .Count property.
    VB Code:
    1. Dim FS As New FileSystemObject
    2.     Dim FSfile
    3.     Dim FSfolder As Folder
    4.     Dim subfolder As Folder
    5.    
    6.     Set FSfolder = FS.GetFolder("C:\Estimates")
    7.         MsgBox "Files are: " & FSfolder.Files.Count
    8.     Set FSfolder = Nothing
    9. End Sub
    Save the last number used in the Registry / a file.
    <<Look up the GetSettings and SaveSettings commands>>

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