Counting files and creating a new
#1

hi

How to make a script which will count files in folder, and create a new?
For example, I have 10 files in one folder. And all files has a name 1.ini, 2.ini, 3.ini.....10.ini.
So, how to count files in folder, or count numbers (1.ini, 2.ini ...) and create a new for one number bigger than previous?

Thanks, and sorry for my bad English
Reply
#2

Can't realy help unless we know what file system you use, for the native file functions (or most other file systems), you could do something simalar to this,
pawn Код:
new fcount;//global
#define MAX_FILES 50

for(new i = 1; i < MAX_FILES; i++)//note i initialised at 1 because thats what it said in ur post,
{                                 //if you have "0.ini" change it.
    new
        str[12];       
    format(str, 12, "%d.ini", i);
    if(fexist(str))
        fcount++;
    else
        break;
}
Now you can use "fcount" it will hold the number of the last file. To create a new one add one to its value, and use that result - as a name for the file. You could also put that in a function make "fcount" local to the function and use it as a return value.
Reply
#3

Thanks man, I will try to use it
Reply
#4

Your welcome i hope it works for you. There are ways it could be made faster but thats the most simple way i could think of.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)