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