AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   open_dir,close_dir (https://forums.alliedmods.net/showthread.php?t=135752)

Guppy488 08-19-2010 10:11

open_dir,close_dir
 
can anyone teach me how to use read_dir , open_dir or close_dir???
i don't know how to use it,i've read from the amxmodx.org's function guide..:cry:
need help ty.

Arkshine 08-19-2010 10:53

Re: read_dir,open_dir,close_dir
 
Don't use read_dir(), it's a deprecated function since it's very slow. You need to use open_dir() + next_file().

A small example with the configs/ directory :

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     new dirPath [ 26 ];     get_configsdir( dirPath, charsmax( dirPath ) );     new fileName[ 32 ];     new handleDir = open_dir( dirPath, fileName, charsmax( fileName ) );         if ( !handleDir )     {         // directory was not found or unable to open it.         return;     }         do     {         // It will loop through all the found files.         server_print( "Filename : %s", fileName );     }       while ( next_file( handleDir, fileName, charsmax( fileName ) ) );         // Don't forget to close if the directory was opened successful.     close_dir( handleDir ); }

Guppy488 08-19-2010 17:32

Re: read_dir,open_dir,close_dir
 
so can you tell me why i could't open without open_dir,close_dir?

Code:

#include <amxmodx>
#include <amxmisc>

new g_FileLocation[]="data.txt"

public plugin_init()
{
    register_plugin("show motd", "1.0", "Guppy488")
    register_clcmd("say /data", "data") // Say
  register_clcmd("say_team /data", "data") //Team Say
    register_clcmd("amx_data", "data") //Console command
   
}

public data(id)
{   
    show_motd(id,g_FileLocation,"Data")
    return PLUGIN_HANDLED
}


Arkshine 08-19-2010 17:34

Re: read_dir,open_dir,close_dir
 
what?

Hunter-Digital 08-19-2010 17:42

Re: read_dir,open_dir,close_dir
 
*_dir are for DIRECTORIES (folders), search in funcwiki for "file" to see functions that relate to reading files in amxx to process their info using amxx... for whatever reason.

Your code, however, does nothing of such, it only opens a MOTD window and displays the contents of "data.txt" file to a player.

I don't see any revelance of motd when the thread is about directories... and, as one said once: what ?

:lol:

Guppy488 08-19-2010 17:46

Re: read_dir,open_dir,close_dir
 
so my plugin does not need "open_dir or close_dir" ? and i can't seem to make it work,when i type /data ,it shows data.txt only..

RedRobster 08-19-2010 18:16

Re: open_dir,close_dir
 
That's all your code has it doing...

Hunter-Digital 08-19-2010 21:00

Re: open_dir,close_dir
 
Clearly I'm wasting my... typing.
I already explained what does what, but you still ask a stupid question, what can I do.

GXLZPGX 08-19-2010 21:27

Re: read_dir,open_dir,close_dir
 
Quote:

Originally Posted by Hunter-Digital (Post 1276041)
*_dir are for DIRECTORIES (folders), search in funcwiki for "file" to see functions that relate to reading files in amxx to process their info using amxx... for whatever reason.

Your code, however, does nothing of such, it only opens a MOTD window and displays the contents of "data.txt" file to a player.

I don't see any revelance of motd when the thread is about directories... and, as one said once: what ?

:lol:

I'll dumb it down for him.

open_dir = open directory. A directory is a folder that holds files or other directories.

You want to open a FILE, not a DIRECTORY.

Kreation 08-19-2010 23:42

Re: read_dir,open_dir,close_dir
 
Quote:

Originally Posted by GXLZPGX (Post 1276232)
I'll dumb it down for him.

open_dir = open directory. A directory is a folder that holds files or other directories.

You want to open a FILE, not a DIRECTORY.

But you must open a directory to open a file, sir.


All times are GMT -4. The time now is 22:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.