Ejemplo n.º 1
0
BOOL
TSHPath::IsDirectoryEmpty(LPCTSTR pszPath)
{
  static TModuleProc1<BOOL,LPCTSTR>
         isDirectoryEmpty(GetModule(), IsDirectoryEmptyStr);
  return isDirectoryEmpty(pszPath);
}
Ejemplo n.º 2
0
void recursiveDirTraverser( char *entry ){
	
	DIR *pDir;
	struct dirent *pDirent;

	pDir = opendir(entry);
	if(pDir == NULL){
		printf("%sinvalid directory or file:%s %s\n", KRED, KNRM, entry);
		exit(0);
	}
	if((pDirent = readdir(pDir)) == NULL ){
		return;
	}
	if( pDirent->d_type == 8 ){
		char path[PATH_MAX];
		if ((getcwd(path, PATH_MAX)) == NULL) {
	          	perror("pwd");
			exit(1);
		}

		strcat(path, "/");
		strcat(path, pDirent->d_name);
        		
		indexFile ( path );
	}

	
	chdir(entry);

	while( pDirent ){
		if(strcmp(pDirent->d_name, ".")  == 0 || strcmp(pDirent->d_name, "..") == 0 ) {
			pDirent = readdir(pDir);
		          continue;
		 }

		/* d_type == 8 when text file,
		 * if(S_ISREG(statbuf.st_mode)) 
		 */
		if( pDirent->d_type == 8 ){

			char path[PATH_MAX];
			if ((getcwd(path, PATH_MAX)) == NULL) {
		          	perror("pwd");
				exit(1);
			}
			strcat(path, "/");
			strcat(path, pDirent->d_name);
	        		
	        		// pDirent->d_name,
			indexFile ( path );

		/* d_type == 4 when dir
		 * if(S_ISDIR(statbuf.st_mode)) 
		 */
		} else if( pDirent->d_type == 4 ) {

			// if dir has no file
			if(!isDirectoryEmpty(pDirent->d_name)){

				char path[PATH_MAX];
				if ((getcwd(path, PATH_MAX)) == NULL) {
			          	perror("pwd");
					exit(1);
				}
				
				recursiveDirTraverser( pDirent->d_name ); 
				chdir(path);
			}

			chdir(entry); 
		} else {
			/* shouldn't happen */
			printf("errer: pDirent->d_type: %d.\n", pDirent->d_type);
		}

		//redirectd pDir to each file or dir	
		if((pDirent = readdir(pDir)) == NULL ){
			closedir(pDir);
			return;
		}
	}
	closedir(pDir);
	return;
}