Outputting the files from a folder and then numbering them
So ive been able to output files from a folder but now i want to number them 1 to 12 but im not sure how. i tried with this for loop and it kinda works, it does number them from 1 to 12 but it does it to each file 12 times so like:
1.file1
2.file1
3.file1
all the way up to 12 and then
1.file2
2.file2
3.file2
up to 12 and so on
13 Replies
how do i make it so it lists each file 1 to 12 just once?
like
1.file1
2.file2
3.file3
Well, my first question is why 12?
because i have 12 files in that folder
But what if that changes? It's better to use the number of files in that folder
no it will always stay the same
i dont wanna add to it or anything
Still, avoid hardcodeing it to 12.
oh thats fine, in the for loop i made it to the fileNames.length anyways so that should be fine?
but its not working as stated above
Well your code is... Fucked up.
ignore the while on the bottom- ehhh?
You have both a foreach and a for
On the same line.
oh yeah..
im not sure how to seperate it so that it does what i want
any tips?
well, I'd use a for loop to loop over
fileNames
, and display their index+1
then you take the users input, parse it as an int, reduce it by 1 and.. you have the indexok i figured it out, thanks!