C
C#7mo ago
Ewan

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
No description
13 Replies
Ewan
Ewan7mo ago
how do i make it so it lists each file 1 to 12 just once? like 1.file1 2.file2 3.file3
Pobiega
Pobiega7mo ago
Well, my first question is why 12?
Ewan
Ewan7mo ago
because i have 12 files in that folder
Pobiega
Pobiega7mo ago
But what if that changes? It's better to use the number of files in that folder
Ewan
Ewan7mo ago
no it will always stay the same i dont wanna add to it or anything
Pobiega
Pobiega7mo ago
Still, avoid hardcodeing it to 12.
Ewan
Ewan7mo ago
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
Pobiega
Pobiega7mo ago
Well your code is... Fucked up.
Ewan
Ewan7mo ago
ignore the while on the bottom- ehhh?
Pobiega
Pobiega7mo ago
You have both a foreach and a for On the same line.
Ewan
Ewan7mo ago
oh yeah.. im not sure how to seperate it so that it does what i want any tips?
Pobiega
Pobiega7mo ago
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 index
Ewan
Ewan7mo ago
ok i figured it out, thanks!