Raised This Month: $51 Target: $400
 12% 

Write the full path to the file into an array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drimacus
Member
Join Date: Jun 2011
Old 02-19-2024 , 12:37   Write the full path to the file into an array
Reply With Quote #1

Hello!
Please tell me how to write the full path of a file into an array. Example: sound/hit/hit1.wav
I managed to write only the file name.
PHP Code:
#include <sourcemod>

#define MAX_PATH_LENGTH 128

ArrayList g_hGlobalArray;

...

public 
OnPluginStart()
{
    
RegConsoleCmd("test"ShowFiles2"");

    new 
Handle:dir OpenDirectory("sound/hit/");
    
g_hGlobalArray = new ArrayList(ByteCountToCells(128));
    if (
dir != INVALID_HANDLE)
    {
        
decl String:Name[MAX_PATH_LENGTH];
        new 
FileType:type;
        while (
ReadDirEntry(dirNameMAX_PATH_LENGTHtype))
        {
            if (
type == FileType_File
                
g_hGlobalArray.PushString(Name);
        }
        
CloseHandle(dir);
    }
}

public 
Action ShowFiles2(clientargs)
{
    
int iSize;
    
char szBuffer[MAX_PATH_LENGTH];
    
iSize g_hGlobalArray.Length;
    
PrintToServer("Size(GlobalArray) = %i"iSize);
    for (new 
0iSize; ++i)
    {
        
g_hGlobalArray.GetString(iszBuffersizeof(szBuffer));
        
PrintToServer("GlobalArray[%i] = '%s'"iszBuffer);
    }


Last edited by Drimacus; 02-19-2024 at 12:39.
Drimacus is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 02-19-2024 , 12:44   Re: Write the full path to the file into an array
Reply With Quote #2

char path[PLATFORM_MAX_PATH];
FormatEx(path, sizeof(path), "%s%s", dir, Name);
g_hGlobalArray.PushString(path);

Something like this inside your while.
Some notes:
is not a good practise creating "big" strings inside a while/for
the ByteCountToCells size should match the MAX_PATH_LENGTH/PLATFORM_MAX_PATH, otherwise may have situations where it truncates
__________________

Last edited by Marttt; 02-19-2024 at 12:44.
Marttt 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 16:01.


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