Highlighted
Contributor.
Contributor.
416 views

Truclient: Use of directory functions

Hi Team,

I am trying to get a count of files within a directory in LR truclient. So i have used the directory functions Say opendir() and readdir().

To use this fucntions i have added the dirent.h and _mingw.h files explicitly and placed in vugen-> include folder but still i am getting the following errors:

How can i solve these? or can i get a count of file within a directory without using the directory functions?

  1. Error:   d:\poornima\truclient2\\pre_cci.c: C:\\Program Files (x86)\\HPE\\Virtual User Generator\\include/dirent.h:60: error: syntax error; found `opendir' expecting `;'    TruClient2
  2. Error:   d:\poornima\truclient2\\pre_cci.c: C:\\Program Files (x86)\\HPE\\Virtual User Generator\\include/dirent.h:61: error: redeclaration of `__cdecl' previously declared at C:\\Program Files (x86)\\HPE\\Virtual User Generator\\include/dirent.h:60     TruClient2
  3. Error:   d:\poornima\truclient2\\pre_cci.c: C:\\Program Files (x86)\\HPE\\Virtual User Generator\\include/dirent.h:61: error: syntax error; found `readdir' expecting `;'    TruClient2

Thanks,

0 Likes
2 Replies
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: Truclient: Use of directory functions

Hi Poornima,

Judging from the error, it seems a ";" character is missing.

Have you closed your statements with semicolons ";" ?

Lup.

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Truclient: Use of directory functions

In the discussion TruClient - Files count in specific folder is a link posted to all existing C functions. This list does not contain the functions you like to use. Adding a non-LR header file without supplying a library to load does not make sense.

If you have a library to access directory info, just put the prototypes of the function in your C file without an include.

As far as I can see there are no functions to list the content of a directoy in the LR C API.

You might try to use something like:

#define INVALID_HANDLE_VALUE ((void*)-1)
#define MAX_PATH 260

typedef int BOOL;
typedef void* HANDLE;
typedef char CHAR;
//typedef char* LPCSTR;
typedef struct _FILETIME {
  DWORD dwLowDateTime;
  DWORD dwHighDateTime;
} FILETIME, *PFILETIME;

typedef struct _WIN32_FIND_DATAA {
  DWORD    dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD    nFileSizeHigh;
  DWORD    nFileSizeLow;
  DWORD    dwReserved0;
  DWORD    dwReserved1;
  CHAR     cFileName[MAX_PATH];
  CHAR     cAlternateFileName[14];
  DWORD    dwFileType;
  DWORD    dwCreatorType;
  WORD     wFinderFlags;
} WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;


HANDLE FindFirstFileA(
  LPCSTR             lpFileName,
  LPWIN32_FIND_DATAA lpFindFileData
);

BOOL FindNextFileA(
  HANDLE             hFindFile,
  LPWIN32_FIND_DATAA lpFindFileData
);

BOOL FindClose(
  HANDLE hFindFile
);


vuser_init()
{
	WIN32_FIND_DATAA buf;
	HANDLE h;
	int count = 0;
	char *dir = "C:/Temp/*";
	
	lr_load_dll("Kernel32.dll");

	h = FindFirstFileA(dir, &buf);
	if( h == INVALID_HANDLE_VALUE ) {
		lr_error_message("Directory %s opened with error %d", dir, GetLastError() );
	} else {
		while( FindNextFileA(h, &buf ) ) {
			count++;
		}
		lr_message("Directory %s has %d entries", dir, count);
		FindClose(h);
	}
}	

See Microsoft documentation for more details.

Signature:
Reward community members who take time to respond and help.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.