473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Generating Sequence numbers

38
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
Oct 11 '07 #1
6 1222
Shashi Sadasivan
1,435 Expert 1GB
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
Oct 11 '07 #2
jaleel
38
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
Oct 11 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
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......,filename99.txt,filename100.tx t
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
Oct 11 '07 #4
jaleel
38
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,.......filename10.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
Oct 11 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
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
Oct 11 '07 #6
Plater
7,872 Expert 4TB
You can use Directory.GetFiles() to get filenames of any pattern.
Then you could sort them by name and look at the last one?
Oct 11 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ross MacGregor | last post by:
I have a very simple yet complicated problem. I want to generate a random list of indices (int's) for a container. Let's say I have a container with 10 items and I want a list of 3 random...
7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
4
by: pauljwilliams | last post by:
Hi there, I'm looking for an algorithm that will generate combinations in the following way: Given a lower bound, and an upper bound, generate a set of size n containing all combinates of...
6
by: Poul Møller Hansen | last post by:
I have made a stored procedure, containing this part for generating a unique reference number. SET i = 0; REPEAT SET i = i + 1; SELECT RAND() INTO reference FROM SYSIBM.SYSDUMMY1; SET...
4
by: Kamran K | last post by:
Hello I have created a client server application using C#. Existing application is using random number on client side to generate sequence numbers that are then assigned to transactions. This...
4
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from...
1
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
3
by: mphil.star | last post by:
I am creating a certain program and in that program i want to add a field which will be creating numbers with text in sequence older " Like MPL 001/08 to unlimited " And 08 be current year. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.