I have about 150 files in a directory. How can I rename all them in a loop? (Ex: 1.mp3, 2.mp3, etc.)
Printable View
I have about 150 files in a directory. How can I rename all them in a loop? (Ex: 1.mp3, 2.mp3, etc.)
include <stdio.h>
...
for(...){
...
result=rename(old,new);
..}
I know that part, but I don't know all the file names. What I want to do is this:
1. Get first file name
2. Rename to i.mp3
3. i++
4. Get next file
...and so on until all files have been renamed. I know you can do this in PHP.
Code:HANDLE f;
WIN32_FIND_DATA g;
TCHAR h = "c:\whatever\*.*";
LPWIN32_FIND_DATA gptr = g;
f=FindFirstFile(h,g);
// you now have a file name in g.cFileName
// find the rest of the files
while(FindFileNext(f,g) ){
// process your next file name here
}
FindClose(gptr);// do this or risk a crash of the PC later on
Thanks for the help :)