I wanted to write a program where I can create text files with consecutive numbers, Following is my code for creating text files with the names "1.txt , 2.txt... to 10.txt"
but all I am getting are files with 0.txt 00.txt , 000.txt etc.
Can Anyone help with this ?
Line 17: fileName is always 0, hence you get only 0. You need to use i and ss needs to be a local variable within the loop. Otherwise the number is added.
I prefer to have filenames with leading zeros, e.g 09 rather than just 9, this makes sorting them into filename sequence more convenient (otherwise you get 1 and 10 together, then 2, 3, 4 etc.
otherwise you get 1 and 10 together, then 2, 3, 4 etc.
Only if you have unintelligent sorting behaviour.
Does Windows still do that?
Linux GUIs usually sort intelligently.
And in the terminal, the -v flag to ls sorts numeric substrings properly.
BTW, your make_name function would be more generally useful if it took a third parameter to pass to setw().
yes, windows still sorts it as text strings.
I saw a 100 line batch file online to resolve it, so its fixable using only the shell, but its ugly.
the gui after (winxp? 2000? unclear?) some point sorts them smart like unix but the shell seems to lack the ability. You can of course make a micro C program to do it or use a windows compatible ls tool.
Regarding file-name sequencing, I wasn't thinking of the OS, rather of various pieces of software such as image browsers or audio file processors, which may have idiosyncrasies of their own. Using a fixed-width for sequence numbers tends to work more predictably, without having to go to extra effort later.