The test environment is Linux system and C.
These interfaces can be used in wasm project to check files in virtual memory.

#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>

int TraverseDir_Num(const char* strVideoDir)
{
	static  int num = 0;
	DIR*		dp;
	struct dirent *entry;
	struct stat statbuf;
	dp = opendir(strVideoDir);
	if(!dp)
	{
		LOG( ERR, "open failed: ", strVideoDir);
		return -1;
	}
	chdir(strVideoDir);
	while((entry = readdir(dp)) != nullptr)
	{
		lstat(entry->d_name, &statbuf);
		if(S_ISDIR(statbuf.st_mode))
		{
			if(!strcmp(".",entry->d_name) || !strcmp("..",entry->d_name))
			{
				continue;
			}
			char	strNewDir[256];
			sprintf(strNewDir, "%s/%s", strVideoDir, entry->d_name);
			TraverseDir_Num(strNewDir);
		}
		else
		{
			num += 1;
		} 
	};
	
	chdir("..");
	closedir(dp);
	return num;
}

void LoadMyData(const std::string path)
{
    std::string folder = "test/case/";
    auto result = access( folder.c_str(), F_OK );
    if( 0 == result ) //On success (all requested permissions granted), zero is returned
    {
        LOG( INFO, "has folder: ", folder );
    }
    else
    {
        LOG( ERR, "has not folder: ", folder );
    }

    folder = "test/case/Setting Data1";
    result = access( folder.c_str(), F_OK );
    if( 0 == result )
    {
        LOG( INFO, "has folder: ", folder );
    }
    else
    {
        LOG( ERR, "has not folder: ", folder );
    }
    
    folder = "test/case/Setting Data2";
    result = access( folder.c_str(), F_OK );
    if( 0 == result )
    {
        LOG( INFO, "has folder: ", folder );
    }
    else
    {
        LOG( ERR, "has not folder: ", folder );
    }

    folder = "test/case/Setting Data1/tooth3.mtc";
    result = access( folder.c_str(), F_OK );
    if( 0 == result )
    {
        LOG( INFO, "has file: ", folder );
    }
    else
    {
        LOG( ERR, "has not file: ", folder );
    }

    int filesCount = TraverseDir_Num( "test/case/Setting Data1" );
    LOG( INFO, "files in setting data1: ", filesCount );

    // ...
}

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

XML To JSON
: Input your strings, the tool can convert XML to JSON for you.

X
0
Would love your thoughts, please comment.x
()
x