Example #1
0
void printdir(char *dir, int depth)
{
	DIR *pd;
	pd = opendir(dir);
	if(pd == NULL)
	{
		printf("open file is fail\n");
		exit(1);
	} 
	chdir(dir);
	struct dirent *entry;
	struct stat statbuf;
	while((entry = readdir(pd)) != NULL )
	{
		stat(entry->d_name, &statbuf);
		if(S_ISDIR(statbuf.st_mode))
		{
			if( !strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
				continue;
			printf("%*s%s/\n",depth,"",entry->d_name);
			printdir(entry->d_name, depth+4);
		}else{
			printf("%*s%s\n",depth,"",entry->d_name);
		}
	}
	chdir("..");
	closedir(pd);
}
Example #2
0
int main() {
	printf( "Directory scan of /home:\n" );
	printdir( "/home", 0 );
	printf( "done.\n" );

	exit( 0 );
}
Example #3
0
void printdir(char *dir, int depth)
{
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;
	char infile[100];

    if((dp = opendir(dir)) == NULL) {
        fprintf(stderr,"cannot open directory: %s\n", dir);
        return;
    }
    chdir(dir);
    while((entry = readdir(dp)) != NULL) {
        lstat(entry->d_name,&statbuf);
        if(S_ISDIR(statbuf.st_mode)) {
            if(strcmp(".",entry->d_name) == 0 || 
                strcmp("..",entry->d_name) == 0)
                continue;
            printdir(entry->d_name,depth+4);
        }
        else
		{
	
		strcpy(infile, DIRPATH);
		strcat(infile, dir);
		strcat(infile, "/");
		strcat(infile, entry->d_name);
		insert_pic(infile);
		}
    }
    chdir("..");
    closedir(dp);
}
Example #4
0
void printdir(char *dir, int depth = 0)
{
//#if LIKE_NIX
    
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;
    
    if ((dp = opendir(dir)) == NULL) {
        fprintf(stderr, "Can`t open directory %s\n", dir);
        return ;
    }
    
    chdir(dir);
    while ((entry = readdir(dp)) != NULL) {
        lstat(entry->d_name, &statbuf);
        if (S_ISDIR(statbuf.st_mode)) {
            if (strcmp(entry->d_name, ".") == 0 ||
                strcmp(entry->d_name, "..") == 0 )
                continue;
            printf("%*s%s/\n", depth, "", entry->d_name);
            printdir(entry->d_name, depth+4);
        } else
            printf("%*s%s\n", depth, "", entry->d_name);
    }
    chdir("..");
    closedir(dp);
//#endif
}
Example #5
0
void printdir(char *dir, int depth)
{
    DIR *dp;
    struct dirent *entry;//定义dirent结构体
    struct stat statbuf;//定义了stat结构体

    if((dp = opendir(dir)) == NULL) {
        fprintf(stderr,"cannot open directory: %s\n", dir);
        return;
    }
    chdir(dir);//相当于cd命令
    while((entry = readdir(dp)) != NULL) {
        lstat(entry->d_name,&statbuf);//作用,将readdir 结构体中的d—name,放入stat 结构体;
        if(S_ISDIR(statbuf.st_mode)) {//调用内部宏函数 S_ISDIR,来判断类型是否为目录
            /* Found a directory, but ignore . and .. */
            if(strcmp(".",entry->d_name) == 0 || 
                strcmp("..",entry->d_name) == 0)
                continue;
            printf("%*s%s/\n",depth,"",entry->d_name);
            /* Recurse at a new indent level */
            printdir(entry->d_name,depth+4);
        }
        else printf("%*s%s\n",depth,"",entry->d_name);
    }
    chdir("..");
    closedir(dp);
}
Example #6
0
int main (void) {
    int arr[SIZE][SIZE];

    srand (time(NULL));

    int i, j;
    i = 0;
    while (i < SIZE) {
        j = 0;
        while (j < SIZE) {
            arr[i][j] = rand() % 25;
            j++;
        }
        i++;
    }

    printarr (arr);

    // Start DP magic?
    // i have no idea what i'm doing but it works
    printf ("Maximal sum is %d\n", DP (arr, 0, SIZE-1));

    printdir (dir);

    return EXIT_SUCCESS;
}
Example #7
0
void printdir(char *dir, int depth)
{
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;

    if((dp = opendir(dir)) == NULL) {
        fprintf(stderr,"cannot open directory: %s\n", dir);
        return;
    }
    chdir(dir);
    while((entry = readdir(dp)) != NULL) {
        lstat(entry->d_name,&statbuf);
        if(S_ISDIR(statbuf.st_mode)) {
      
            if(strcmp(".",entry->d_name) == 0 || 
                strcmp("..",entry->d_name) == 0)
                continue;
            printf("%*s%s/\n",depth,"",entry->d_name);
           
            printdir(entry->d_name,depth+4);
        }
        else printf("%*s%s:%d\n",depth,"",entry->d_name,statbuf.st_size);
            
    }
    chdir("..");
    closedir(dp);
}
Example #8
0
void printdir(char *dir, int depth)
{
	DIR *dp; // directory pointer
	struct dirent *entry; 
	struct stat statbuf; // stat buffer

	//if pointer to directory does not exist
	//return an error message
	if ((dp = opendir(dir)) == NULL) {
		fprintf(stderr, "ERROR: COULD NOT OPEN DIRECTORY - %s\n", dir);
		return;
	}

	// change directories
	chdir(dir);
	while((entry = readdir(dp)) != NULL) {
		lstat(entry->d_name, &statbuf);
		if (S_ISDIR(statbuf.st_mode)) {
			/* FOUND A DIRECTORY BUT IGNORE . and .. */
			if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0) continue;
			printf("%*s%s/\n", depth, "", entry->d_name);
			/* RECURSE  AT A NEW INDENT LEVEL */
			printdir(entry->d_name, depth+6);
		} else	printf("%*s%s\n", depth, "", entry->d_name);
	}
	// change directories down into sub-directories
	chdir("..");
	closedir(dp); // close the directory using the pont to the dir
}
Example #9
0
int main()
{
    printf ("Directory scan of ~:\n");
    printdir ("/tmp",0);
    printf ("done.\n");
    exit (0);
}
Example #10
0
void printdir(char *dir, int depth)
{
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;
    if((dp = opendir(dir)) == NULL) 
    {
        fprintf(stderr,"cannot open directory: %s\n", dir);
        return;
    }
    chdir(dir);
    while((entry = readdir(dp)) != NULL) 
    {
        lstat(entry->d_name,&statbuf);
        if(S_ISDIR(statbuf.st_mode)) 
        {
            /* Found a directory, but ignore . and .. */
            if(strcmp(".",entry->d_name) == 0 ||strcmp("..",entry->d_name) == 0)
                continue;
            printf("%*s%s/\n",depth,"",entry->d_name);
            /* Recurse at a new indent level */
            printdir(entry->d_name,depth+4);
        }
        else 
            printf("%*s%s\n",depth,"",entry->d_name);
    }   
    chdir("..");
    closedir(dp);
}
Example #11
0
int main(void)
{
    printf("Directory scan of /home \n");
    printdir("/home/chenhai/python",0);
    printf("done.\n");
    return 0;
}
Example #12
0
void printdir(char *dir,int depth)
{
	DIR *dp;
	struct dirent *entry;
	struct stat statbuf;
	if((dp=opendir(dir))==NULL)
	{
		printf("The %s can't open'",dir);
		exit(-1);
	}
	chdir(dir);
	while((entry=readdir(dp))!=NULL){
		lstat(entry->d_name,&statbuf);
		if(S_ISDIR(statbuf.st_mode))
		if(strcmp(".",entry->d_name)==0||strcmp("..",entry->d_name)==0)
			continue;
		else	
		{
			printf("%*s%s\n",depth,"",entry->d_name);
			printdir(entry->d_name,depth+4);
		}

		else 
			printf("%*s%s\n",depth,"",entry->d_name);
	}
	chdir("..");//chdir函数的参数是字符串类型的指针。
	closedir(dp);	
}
Example #13
0
int main(int argc , char *argv[])
{
    printf("Directory scan of /home:\n");
    //char *addr = argv[1];
    printdir(argv[1],0);
    printf("done.\n");
    exit(0);
}
Example #14
0
// Main
int main()
{
	printf("Directory scan of /home: \n");
	printdir("/home", 0);
	printf("Done scanning. \n");

	return 0;
}
int main()
{
    printf("Directory scan of /home:\n");
    printdir("/Users/pabitraadhikari/Desktop",0);
    printf("done.\n");
    
    exit(0);
}
Example #16
0
int main()
{
	printf("Directory scan of /home/nickli/dirtest:\n");
	printdir("/home/nickli/dirtest",0);
	printf("done.\n");
	
	exit(0);	
}
Example #17
0
int	main(int argc,char **argv)
{
		char *topdir=".";
		if(argc>=2)
			topdir=argv[1];

		printf("Directory scan is:%s\n",topdir);
		printdir(topdir,0);
		printf("done.\n");
}
void complete_printdir( char *path )
{
  DIR *the_dir;
  int status;

  the_dir = opendir( path );
  rtems_test_assert( the_dir );
  printdir( the_dir );
  status = closedir( the_dir );
}
Example #19
0
int main(int argc,char* argv[]){
	char *topdir,pwd[2]=".";
	if(argc<2)
		topdir=pwd;
	else
		topdir=argv[1];
	printf("Directory scan of %s\n",topdir);
	printdir(topdir,0);
	printf("\ndone.\n");
	return 0;
}
Example #20
0
int main(int argc, char* argv[])
{
    char *topdir = ".";
    if (argc >=2)
        topdir = argv[1];

    printf("Directory scan of %s\n", topdir);
    printdir(topdir, 0);
    printf("Done.\n");
    exit(0);
}
Example #21
0
int main(int argc, char **argv)
{
	if (2 != argc)
	{
		fprintf(stderr, "One parameter should be specified.\n");
		exit(1);
	}

	printf("Directory scan of %s.\n", argv[1]);
	printdir(argv[1], 0);
	printf("done.\n");

	exit(0);
}
Example #22
0
int main(int argc, char * argv[])
{
	if (argc != 2) return 1;

	LINUX_DIR * dir = getdents_opendir(argv[1]);
	if (dir == NULL)
	{
		perror("getdents_opendir");
		return 1;
	}


	printdir(dir);
	long int pos = getdents_telldir(dir);
	printf("getdents_telldir ==  %ld\n", pos);
	getdents_seekdir(dir, pos);
	getdents_seekdir(dir, 3);
	printdir(dir);

	getdents_closedir(dir);

	return 0;
}
Example #23
0
void printdir(char *dir, int depth){
	DIR *dp;
	struct dirent *entry;
	struct stat statbuf;

	/* dir에 저장된 이름의 디렉토리를 열고 그에 대한 디렉토리 스트림을 생성 */
	if((dp = opendir(dir)) == NULL) {
		fprintf(stderr, "cannot open directory: %s\n", dir);
		return ;
	}
	
	/* 현재 작업 디렉토리를 dir로 변경 */
	chdir(dir);

	/* dp로 지정된 디렉토리 스트림 안의 다음 디렉토리 항목에 대한 구조체의 포인터를 entry에 저장.
	연달아 호출함으로써 여러 디렉토리 항목들에 차례로 접근할 수 있다.*/
	while((entry = readdir(dp)) != NULL) {
		/* entry->d_name에 저장된 이름을 갖는 파일의 상태 정보를 statbuf에 저장한다. */
		lstat(entry->d_name, &statbuf);

		/* 저장된 파일의 상태 정보를 통해 디렉토리 여부를 검사 */
		if(S_ISDIR(statbuf.st_mode)) {
			/* Found a directory, but ignore . and .. */
			if(strcmp(".", entry->d_name) == 0 ||
				strcmp("..", entry->d_name) ==0) continue;

			/* ignore hidden directory*/
			if(entry->d_name[0]=='.') continue;			
	
			printf("%*s%s/\n", depth, "", entry->d_name);

			/* 현재 디렉토리의 하위 디렉토리를 탐색하기 위한 재귀호출.
			하위 디렉토리를 들여쓰기하기 위해 depth+4를 전달한다. */
			printdir(entry->d_name, depth+4);
		} else {
			
			// ignore hidden file	
			if(entry->d_name[0] == '.') continue;
			printf("%*s%s\n", depth, "", entry->d_name);
		}
	}

	/* printdir 함수로 진입 전에 작업하던 디렉토리로 이동 */
	chdir("..");

	/* 디렉토리 스트림을 닫고 그에 연관된 자원들을 해제한다.
	성공 시 0, 오류 발생 시 -1을 반환한다. */
	closedir(dp);
}
Example #24
0
int main(int argc, char **argv)
{
	while(--argc)
	{
    	printdir(argv[argc],0);//处理第一个起始位置
		
		if(argc-1)//当前处理的参数不是最后1个参数
		{
			printf("The next [%s] ?(y/n)\n",argv[argc-1]);
			char choice;
			choice = getchar();
			while((getchar()) != '\n');//吃掉多余字符
			if(choice == 'n') break;//退出while
		}
	}
    exit(0);
}
Example #25
0
void lsdir(char *o, size_t size, const char *path, int recurse, int want_ctime)
{
	struct jffs2_raw_dirent *dd;
	struct dir *d = NULL;

	uint32_t ino;

	dd = resolvepath(o, size, 1, path, &ino);

	if (ino == 0 ||
			(dd == NULL && ino == 0) || (dd != NULL && dd->type != DT_DIR))
		errmsg_die("%s: No such file or directory", path);

	d = collectdir(o, size, ino, d);
	printdir(o, size, d, path, recurse, want_ctime);
	freedir(d);
}
Example #26
0
int px_http_handler (FILE * ds, char * ip) {
	px_url address;
	address.dir = NULL;
	
	if (!validate(ds, &address)) {
		return 0;
	}
	
	char* zeile = (char*)malloc(PX_MAXLINE + 1);
	
	while(fgets(zeile, PX_MAXLINE, ds), px_emptyline(zeile) == 0) {
		printf("%s", zeile);
	}
	
	// Ist die Datei erlaubt?
	if (px_char_count(address.dir, '/') > 1) {
		err403(ds);
		free(zeile);
		return 0;
	}
	
	if (strcmp(address.dir, "/") == 0) {
		fputs("HTTP/1.1 200 OK\nConnection: close\n", ds);
		fputs("Content-Type: text/html\n\n", ds);
		printdir(ds);
		return 0;
	}
	
	if (allowed(address.dir)) {
		char * filename = address.dir;
		if (*filename == '/') filename++;
		if (access(filename, R_OK) != -1) {
			fputs("HTTP/1.1 200 OK\nConnection: close\n", ds);
			deliver(ds, address.dir);
		}
		return 0;
	}
	
	err404(ds);
	
	fputs("\n", ds);
	free(zeile);
	
	return 0;
}
Example #27
0
void printdir(char *dir, int depth)
{
	DIR *dp;

	struct dirent *entry;
	struct stat statbuf;
	
	/* Once enter this function, the dir is sure to be a directory. This is checked before invoking this function. */
	if ((dp = opendir(dir)) == NULL)
	{
		fprintf(stderr, "Can not open directory %s.\n", dir);
		return;
	}

	chdir(dir);

	while ((entry = readdir(dp)) != NULL)
	{
		lstat(entry->d_name, &statbuf);
		if (S_ISDIR(statbuf.st_mode))
		{
			/* Found a directory, but ignore  and .. */
			if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0)
			{
				continue;
			}

			printf("%*s%s/\n", depth, "", entry->d_name);

			/* Recurse at a new indent level */
			/* Why plus depth with 4, not 1 ? */
			printdir(entry->d_name, depth + 4);
		}
		else
		{
			printf("%*s%s\n", depth, "", entry->d_name);
		}
	}

	chdir("..");
	closedir(dp);
}
Example #28
0
File: d.c Project: AaronNGray/cflow
/* Print contents of the directory PREFIX/NAME.
   Prefix each output line with LEVEL spaces. */
void
printdir (int level, char *name)
{
  DIR *dir;
  struct dirent *ent;
  char cwd[512];

  if (!getcwd(cwd, sizeof cwd)) 
    {
      perror ("cannot save cwd\n");
      _exit (1);
    }
  chdir (name);
  dir = opendir (".");
  if (!dir)
    {
      perror (name);
      _exit (1);
    }
  
  while ((ent = readdir (dir)))
    {
      printf ("%*.*s%s", level, level, "", ent->d_name);
      if (ignorent (ent->d_name))
        printf ("\n");
      else if (isdir (ent->d_name))
        {
          printf ("/");
          if (level + 1 == max_level)
            putchar ('\n');
          else
            {
              printf (" contains:\n");
              printdir (level + 1, ent->d_name);
            }
        }
      else
        printf ("\n");
    }
  closedir (dir);
  chdir (cwd);
}
Example #29
0
int main(int argc, char *argv[])
{
  /* ディレクトリ構造を取得する */
  printdir(".",0);
  cd = root;
  show_tree_dfs(root,0);
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
  glutInitWindowSize(500,500);
  glutCreateWindow(WINDOW_NAME);
  init();
  glutDisplayFunc(glut_display);
  glutKeyboardFunc(glut_keyboard);
  glutMouseFunc(glut_mouse);
  glutMotionFunc(glut_motion);
  glutPassiveMotionFunc(glut_motion);
  glutIdleFunc(glut_idle);
  glutMainLoop();
  return 0;
}
Example #30
0
void	handledirs(char **files, char **dir, t_ls_options *opts)
{
	int		i;
	int		first;

	first = 1;
	if (*dir)
	{
		i = 0;
		opt_sort(opts, ".", dir);
		while (dir[i] != NULL && opts->mr == 1)
		{
			ft_bigr(opts, dir[i], 0, &first);
			i++;
		}
		while (dir[i] != NULL)
		{
			printdir(files, dir, opts, i);
			i++;
		}
	}
}