Managing Files In The Host OSThe following file management operations can be performed using the Parallels C API on the host machine:
The file management functionality can be accessed through the Obtaining the host OS directory listing The directory listing is obtained using the // Obtains the entire directory tree in the host OS // starting at the specified path. // The "levels" parameter specifies how many levels should the // function traverse down the directory tree. PRL_RESULT GetHostDirList(PRL_HANDLE hServer, PRL_CONST_STR path, int levels) { PRL_HANDLE hJob = PRL_INVALID_HANDLE; PRL_HANDLE hJobResult = PRL_INVALID_HANDLE; PRL_HANDLE hParentDirectory = PRL_INVALID_HANDLE; PRL_HANDLE hChildElement = PRL_INVALID_HANDLE;
PRL_RESULT ret = PRL_ERR_UNINITIALIZED; PRL_RESULT nJobReturnCode = PRL_ERR_UNINITIALIZED;
// Get directory list from the host. // The second parameter specifies the absolute // path for which to get the directory listing. hJob = PrlSrv_FsGetDirEntries(hServer, path);
// Wait for the job to complete. ret = PrlJob_Wait(hJob, 1000); if (PRL_FAILED(ret)) { // Handle the error... return -1; }
// Analyze the result of PrlSrv_FsGetDirEntries. ret = PrlJob_GetRetCode(hJob, &nJobReturnCode); if (PRL_FAILED(ret)) { // Handle the error... PrlHandle_Free(hJob); return -1; } // Check the job return code. if (PRL_FAILED(nJobReturnCode)) { // Handle the error... PrlHandle_Free(hJob); return -1; }
// Get job result. ret = PrlJob_GetResult(hJob, &hJobResult); PrlHandle_Free(hJob); if (PRL_FAILED(ret)) { // Handle the error... return -1; }
// Get a handle to the parent directory. // This is the directory that we specified in the // PrlSrv_FsGetDirEntries call above. ret = PrlResult_GetParam(hJobResult, &hParentDirectory); PrlHandle_Free(hJobResult); if (PRL_FAILED(ret)) { // Handle the error... return -1; }
// Get parameter count (the number of child entries). PRL_UINT32 nParamCount = 0; ret = PrlFsInfo_GetChildEntriesCount(hParentDirectory, &nParamCount); if (PRL_FAILED(ret)) { // Handle the error... PrlHandle_Free(hJob); return -1; }
// Iterate through the list obtaining // a handle of type PHT_REMOTE_FILESYSTEM_ENTRY // for each child element of the parent directory. for (PRL_UINT32 i = 0; i < nParamCount; ++i) { // Get a handle to the child element. ret = PrlFsInfo_GetChildEntry(hParentDirectory, i, &hChildElement); if (PRL_FAILED(ret)) { // Handle the error... continue; }
// Get the filesystem element name. PRL_CHAR sBuf[1024]; PRL_UINT32 nBufSize = sizeof(sBuf); ret = PrlFsEntry_GetAbsolutePath(hChildElement, sBuf, &nBufSize); if (PRL_FAILED(ret)) { // Handle the error... PrlHandle_Free(hChildElement); continue; }
printf("%s\n", sBuf); PrlHandle_Free(hChildElement);
// Recursive call. Obtains directory listing for // the entry returned in this iteration. if (levels > 0 || levels <= -1) { int count = levels - 1; GetHostDirList(hServer, sBuf, count); } } PrlHandle_Free(hParentDirectory); PrlHandle_Free(hJob);
return PRL_ERR_SUCCESS; } |
||||
|