Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 14:17   while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #1

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 )
      }
gamer99 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-09-2011 , 14:43   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #2

Just add a check.

if( s_Buffer[ 0 ] == "." ) { continue; }
__________________
Arkshine is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 14:58   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #3

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 is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 15:02   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #4

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
gamer99 is offline
Old 08-09-2011, 15:05
Arkshine
This message has been deleted by Arkshine. Reason: nvm
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-09-2011 , 15:14   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #6

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.
__________________
fysiks is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-09-2011 , 15:20   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #7

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 }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 15:21   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #8

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 .
gamer99 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-09-2011 , 15:25   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #9

You can just make a list of the filenames either hardcoded or in an ini file then you can easily track everything from there.
__________________
fysiks is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 15:30   Re: while( next_file( handleDir, s_Buffer, charsmax( s_Buffer ) ))
Reply With Quote #10

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 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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