Hey. I had to copy ~300 map names from my map directory and instead of doing it manually I threw this plugin together in order to do it for me. Thought I'd share
Don't keep this in your server if you don't need it to be. It'll just eat up resources...
PHP Code:
/* This plugin assumes you want the maplist.txt to be OVERWRITTEN *
* Made by Headline & SWAT_88 */
#include <sourcemod>
#pragma newdecls required
#pragma semicolon 1
ArrayList files = null;
public void OnPluginStart()
{
files = new ArrayList(PLATFORM_MAX_PATH);
ReadFileFolder("maps");
File newFile = OpenFile("maplist.txt", "w");
char tempString[PLATFORM_MAX_PATH];
for (int i = 0; i < files.Length; i++)
{
files.GetString(i, tempString, sizeof(tempString));
newFile.WriteLine(tempString);
}
newFile.Close();
}
/* Snippet from SWAT_88 */
public void ReadFileFolder(char[] path)
{
Handle dirh = null;
char buffer[256];
char tmp_path[256];
FileType type = FileType_Unknown;
int len;
len = strlen(path);
if (path[len-1] == '\n')
path[--len] = '\0';
TrimString(path);
if(DirExists(path))
{
dirh = OpenDirectory(path);
while(ReadDirEntry(dirh, buffer, sizeof(buffer), type))
{
len = strlen(buffer);
if (buffer[len-1] == '\n')
buffer[--len] = '\0';
TrimString(buffer);
if (!StrEqual(buffer,"",false) && !StrEqual(buffer,".",false) && !StrEqual(buffer,"..",false))
{
strcopy(tmp_path,255,path);
StrCat(tmp_path,255, "/");
StrCat(tmp_path,255, buffer);
if(type == FileType_File)
{
if (StrContains(tmp_path, ".bsp") != -1)
{
ReplaceString(tmp_path, 255, ".bsp", "");
ReplaceString(tmp_path, 255, "maps/", "");
files.PushString(tmp_path);
}
}
}
}
}
else
{
SetFailState("[Log Cleaner] No log folder found!");
}
if(dirh != null)
{
CloseHandle(dirh);
}
}