AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) )) (https://forums.alliedmods.net/showthread.php?t=164280)

gamer99 08-09-2011 14:17

while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
While doing next_file

I am getting two file with name "." and ".."

How I can do the setting so that I will not get those ?

i m doing like

Code:

while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
    {
        server_print( "Temp Filename : %s", s_Buffer )
      }


Arkshine 08-09-2011 14:43

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
Just add a check.

if( s_Buffer[ 0 ] == "." ) { continue; }

gamer99 08-09-2011 14:58

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
I did but the problem is ....


I need next file of a particular file . For example if I have

001.dll
002.dll
003.dll


Then i have put condition like
Code:

while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
    {
            if(!(containi(s_Buffer,"dll") !=-1) ||equali(s_Buffer,s_Temp) )
                        continue

but whatever is the file, nextfile is "..""
Now as I am doing continue it is again calculating the next file and I am getting only one file each time . The next file of ".."

So how to overcome it . I hope you got my problem

gamer99 08-09-2011 15:02

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
or more clear idea what I am trying to do ...

I am storing a filename is a config file . The file will only hold one line which is the last used filename . So that we can easily calculate the next file .

And we are calculating the next file at each map change . So it's like

1) Retriving the old file name from the config file
2) take the next file
3)delete the old entry from the config file
4) put the new entry

fysiks 08-09-2011 15:14

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
There is no reason to open the directory when you know exactly what is in the directory. Especially if you number your files like you do above. Just add one to that digit. If you go over the maximum then go back to 001.

You are making it way harder than it needs to be.

Also, learn to use the edit button.

Exolent[jNr] 08-09-2011 15:20

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
There are 2 "files" in the directory called "." and ".." meaning current directory and parent directory, respectively.
These 2 "files" are shown first before other files when iterating through directory files.
To skip them, call next_file() before your loop so you won't get them.

Code:
open_dir() // stores "." file into your file var next_file() // stores ".." file into your file var while(next_file()) {     // proper files are listed here }

gamer99 08-09-2011 15:21

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
Actually I posted those names just to make you understand . It can be of any name .

Like

hello.dll

And as I am trying to make it dynamic it should again start from the starting file once the last file reached .

fysiks 08-09-2011 15:25

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
You can just make a list of the filenames either hardcoded or in an ini file then you can easily track everything from there.

gamer99 08-09-2011 15:30

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
Code:

#include <amxmodx>
#include <amxmisc>

new s_FileName[ 32 ]
new s_LastDll[128]
new s_MainOpenGl[] = "../opengl32.dll"

public plugin_init()
{
        new s_ConfigsDir[128],OPENGL_DIR[128],s_Temp[32],s_TempLastDll[128]
        get_configsdir(s_ConfigsDir, sizeof(s_ConfigsDir)-1)
        format (OPENGL_DIR, sizeof(OPENGL_DIR)-1, "%s/opengl", s_ConfigsDir)
        format (s_LastDll, sizeof(s_LastDll)-1, "%s/opengl/lastopengl.dat", s_ConfigsDir)
       
        new handleDir = open_dir( OPENGL_DIR, s_FileName, charsmax( s_FileName ) );
       
        if(!file_exists(s_LastDll))
        {
                write_file(s_LastDll,s_FileName,0)
        }
       
        new s_Buffer[ 32 ] , iLen;
       
        read_file( s_LastDll , 0 , s_Buffer , charsmax( s_Buffer ) , iLen )
        server_print("Current Filename : %s", s_Buffer)
       
        formatex(s_Temp, charsmax(s_Temp),s_Buffer )
       
        format (s_TempLastDll, sizeof(s_TempLastDll)-1, "%s/opengl/%s", s_ConfigsDir,s_Temp)
        if(file_exists(s_MainOpenGl))
        {
                server_print( "file exists : renaming from %s to %s" , s_MainOpenGl,s_TempLastDll )
                rename_file(s_MainOpenGl,s_TempLastDll,1)
        }       
       
        while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
        {
                server_print( "Temp Filename : %s", s_Buffer )
                if(!(containi(s_Buffer,"dll") !=-1) || equali(s_Buffer,s_Temp) )
                        continue
               
                // It will loop through all the found files.
                server_print( "Next Filename : %s", s_Buffer )
                server_print("%s",s_LastDll)
                if(delete_file(s_LastDll))
                        server_print("file deleted")
                else
                        server_print("file is not deleted")
               
                write_file(s_LastDll,s_Buffer,0)
                format (s_TempLastDll, sizeof(s_TempLastDll)-1, "%s/opengl/%s", s_ConfigsDir,s_Buffer)
                server_print( "Moving %s to %s" , s_TempLastDll,s_MainOpenGl )
                rename_file(s_TempLastDll,s_MainOpenGl,1)
                break
        } 
       
        // Don't forget to close if the directory was opened successful.
        close_dir( handleDir );
}


here is the code ...

create one file in config directory and put some dll there . Then start your server , change map . At the time of map change it should take diff diff dll and put it in the base directory

gamer99 08-09-2011 15:32

Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
 
Quote:

Originally Posted by fysiks (Post 1529108)
You can just make a list of the filenames either hardcoded or in an ini file then you can easily track everything from there.

I m also thinking of the same now . it will be easier like recreating the list of file in a .ini file and fetching any random line number from there .


All times are GMT -4. The time now is 03:28.

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