Generating Sequence numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaleel
    New Member
    • Sep 2007
    • 38

    Generating Sequence numbers

    Hi
    I want to generate numbers like 00,01,02,03.... for appending into filename to indicate versions.I cant use Random numbers here. Can anybody help me to resolve this..? Should I use a database or storing latest number in the sequence so that new number can be generated ?....

    Thanks
    jaleel
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Hi,
    You can generate numbers and convert them to strings.
    However with your sequence, what happens after 99 ?

    Are these numbers being placed at the end of the filename?

    With regards to storing the number,
    You could store it into a database or some file (that would be the best solution) or if you are sure that no one has access to add/rename/delete/modify the folder in which you store these files/folders then you could read the filenames and get the last number used.

    cheers
    Last edited by Shashi Sadasivan; Oct 11 '07, 02:34 AM. Reason: regarding storage of number

    Comment

    • jaleel
      New Member
      • Sep 2007
      • 38

      #3
      Thanks shashi,

      Yea , file name is just like : filename00.txt, filename01.txt, ....filename99. txt,fiename100. txt.....

      But if we take from the filename(last written) , how do we know the last filename( in other words , the biggest number generated so far)? What type of comaprison here we can do..?

      Thanks,
      Jaleel

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        well...for starters you may want to consider to use delimiters for version numbers
        so you could name it filename-01.txt
        so that incase your filename ends up with a digit, it dosent merge with the version number.
        Secondly, you just gave your example of filename01.txt. .....,filename9 9.txt,filename1 00.txt
        So whats the use of padding single digits?
        are you comfortable with no padding and nameing your files as filename-1.txt,filename-3.txt....etc

        Now if you do want to get the last value used, based upon the files in the directory, then you will need to read this directory and parse each file, split it using the delimiter and get the version number from that.

        compare them and get the highest of all.

        cheers

        Comment

        • jaleel
          New Member
          • Sep 2007
          • 38

          #5
          Hi Shashi,

          Actually filenames are not for version controlling. Just to identify the sequence in which it wriiten to the filesystem.So I am Ok with filename1.txt, filename2.txt,. ......filename1 0.txt.....


          Now if you do want to get the last value used, based upon the files in the directory, then you will need to read this directory and parse each file, split it using the delimiter and get the version number from that.
          This case will be too time consuming if number of files is high, better to stick with writing the last number to a text file

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            Yes it is,

            And if someone does delete a file, you will know about it :)

            There is another thing. When creating your new filename, check if it already exists (you never know), else you might overwrite the older one

            cheers

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              You can use Directory.GetFi les() to get filenames of any pattern.
              Then you could sort them by name and look at the last one?

              Comment

              Working...