AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Write the full path to the file into an array (https://forums.alliedmods.net/showthread.php?t=346281)

Drimacus 02-19-2024 12:37

Write the full path to the file into an array
 
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);
    }



Marttt 02-19-2024 12:44

Re: Write the full path to the file into an array
 
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


All times are GMT -4. The time now is 15:04.

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