Raised This Month: $ Target: $400
 0% 

Read all files in a folder.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-06-2013 , 11:33   Read all files in a folder.
Reply With Quote #1

Hello everybody,

I'd like to read out the content of all files in a folder, the files aren't registered somewhere.
Basically I want something like this :

PHP Code:
for each file in folder
{
          for 
each line in file
          
{
                    
read out content
                    compare with a string
                    
return true or false if containi
          
}

I know how to do the "for each line in file" part, but I don't know how to get all files in a folder.
__________________
Kia is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 09-06-2013 , 11:38   Re: Read all files in a folder.
Reply With Quote #2

http://www.amxmodx.org/doc/index.htm...2Fread_dir.htm
mottzi is offline
Send a message via MSN to mottzi
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-06-2013 , 12:30   Re: Read all files in a folder.
Reply With Quote #3

Thanks.
__________________
Kia is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 09-06-2013 , 12:34   Re: Read all files in a folder.
Reply With Quote #4

Bether method: http://forums.alliedmods.net/showthread.php?t=135752
mottzi is offline
Send a message via MSN to mottzi
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-06-2013 , 12:46   Re: Read all files in a folder.
Reply With Quote #5

Thanks, I tried to use it, but I get this problem.

Quote:
Couldn't read file "file.txt"
PHP Code:
new szConfigDir[256], szRepoDir[256]
    
get_configsdir(szConfigDircharsmax(szConfigDir))
    
    
formatex(szRepoDircharsmax(szRepoDir), "%s/xRepo/repos/"szConfigDir)
    
    new 
szName[128], szURL[128]
    new 
iLineiLengthsBuffer[256]
    
    new 
szFileName[64]
    new 
hDir open_dir(szRepoDirszFileNamecharsmax(szFileName))
    
    
client_print(idprint_chat"%s"szRepoDir)
    
    if(!
hDir)
        return
    
    do
    {
        while(
read_file(szFileNameiLine++, sBuffercharsmax(sBuffer), iLength)) 
        {
            if((
sBuffer[0] == ';' || !iLength))
                continue
            
            
strtok(sBufferszNamecharsmax(szName), szURLcharsmax(szURL), '|'0)
            
            if(
containi(szNameszPlugin))
                
client_print(idprint_console"%s"szName)
        }
    }
    while ( 
next_filehDirszFileNamecharsmaxszFileName ) ) )
    
close_dir(hDir
__________________
Kia is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 09-06-2013 , 15:04   Re: Read all files in a folder.
Reply With Quote #6

Try some debuging, replace do-while with only while and then skip . and .. from being stored. And also after you have finished from reading one file reset the iLine contor but maybe read_file can do this at every new file you should check.

Last edited by Clauu; 09-06-2013 at 15:11.
Clauu is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-06-2013 , 22:49   Re: Read all files in a folder.
Reply With Quote #7

Quote:
Originally Posted by Kia View Post
Thanks, I tried to use it, but I get this problem.



PHP Code:
new szConfigDir[256], szRepoDir[256]
    
get_configsdir(szConfigDircharsmax(szConfigDir))
    
    
formatex(szRepoDircharsmax(szRepoDir), "%s/xRepo/repos/"szConfigDir)
    
    new 
szName[128], szURL[128]
    new 
iLineiLengthsBuffer[256]
    
    new 
szFileName[64]
    new 
hDir open_dir(szRepoDirszFileNamecharsmax(szFileName))
    
    
client_print(idprint_chat"%s"szRepoDir)
    
    if(!
hDir)
        return
    
    do
    {
        while(
read_file(szFileNameiLine++, sBuffercharsmax(sBuffer), iLength)) 
        {
            if((
sBuffer[0] == ';' || !iLength))
                continue
            
            
strtok(sBufferszNamecharsmax(szName), szURLcharsmax(szURL), '|'0)
            
            if(
containi(szNameszPlugin))
                
client_print(idprint_console"%s"szName)
        }
    }
    while ( 
next_filehDirszFileNamecharsmaxszFileName ) ) )
    
close_dir(hDir
Where do you find this output that you speak of? Does this file actually exist? Also, don't use read_file(). Use fopen(), fgets(), fclose(), etc.
__________________
fysiks is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-07-2013 , 01:48   Re: Read all files in a folder.
Reply With Quote #8

The error is shown in the console while debugging, and the file exists already.
__________________
Kia is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-07-2013 , 02:49   Re: Read all files in a folder.
Reply With Quote #9

Quote:
Originally Posted by Kia View Post
The error is shown in the console while debugging, and the file exists already.
Then I guess you need to start debugging it yourself. First change to the correct file functions. Then, you should use the full filepath as the filename when opening the file.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-07-2013 , 02:54   Re: Read all files in a folder.
Reply With Quote #10

Paths are relative to current folder, you have to format the full one.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

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 18:45.


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