Counting Files in a Directory Using FileManager
#1

I wanna know how to get number of files in a directory using FileManager. I did this but it don't work ...

Код:
stock NumFiles(type2)
{
	new string[50];
	if(type2 == 1) format(string, sizeof(string), "Vehicles/normal/");
	else if(type2 == 3) format(string, sizeof(string), "Vehicles/personal/");
	else if(type2 == 4) format(string, sizeof(string), "Vehicles/faction/");
	else if(type2 == 5) format(string, sizeof(string), "Vehicles/job/");
	else if(type2 == 6) format(string, sizeof(string), "Vehicles/biz/");
	
	new dir:dHandle = dir_open(string);
	new item[40], type, contor = -1;
		
	while(dir_list(dHandle, item, type))
	{
		if(type == FM_FILE) contor++;
	}
			
	dir_close(dHandle);
	return contor;
}
Reply
#2

Try use this stock, I've used it myself in the past:

pawn Код:
// Credits to Swimor's include file: https://sampforum.blast.hk/showthread.php?tid=411268

stock fnum(dir[] = NULL_DIR) {
    new
        idx,
        file[MAX_FILE_NAME];
    while(fname(dir, idx, file)) {
        idx++;
    }
    return idx;
}
And then you can use:

pawn Код:
fnum(dir[Vehicles/normal])
etc..
Reply
#3

This one need RL_Files, but it don't have linux version.
Reply
#4

Quote:
Originally Posted by shaPP
Посмотреть сообщение
This one need RL_Files, but it don't have linux version.
Ah.. I see, my mistake. Sorry. I've searched a bit on the web and couldn't find anything. I'd recommend for each new file you could create a main file and for each new file created, put that main file to it's value and add an extra one on it. It seems complicated, but do something like if you do a specific command to create a new vehicle for example, the main.ini file, inside that, the value will increase by 1, so that'll show how many files are actually in the directory, excluding the main.ini. To set it first time, CTRL + A and then see how many files are there, and then put that value inside main.ini.. confusing...
Reply
#5

I know is possible using this plugin, i asked a version using it ..
Reply
#6

Why don't you ask on the plugin thread?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)