Exemple #1
0
void show_directory(char *directory_name)
 { 
   DIR *directory_pointer;
   struct dirent *entry;

   unsigned attributes;

   if ((directory_pointer = opendir(directory_name)) == NULL)
     printf("Error opening %s\n", directory_name);
   else
     {
        chdir(directory_name);
        while (entry = readdir(directory_pointer))
          {
            attributes = _chmod(entry, 0);
            
            // Check if entry is for a subdirectory and is not "." or ".."
            if ((attributes & FA_DIREC) && 
               (strncmp(entry, ".", 1) != 0))
             { 
               printf("\n\n----%s----\n", entry);
               show_directory(entry);
             }
            else
             printf("%s\n", entry);
          }
        
        closedir(directory_pointer);
        chdir("..");
     }
 }
Exemple #2
0
 void main(void)
  {
    char buffer[MAXPATH];

    // Save current directory so you can restore it later
    getcwd(buffer, sizeof(buffer));
    show_directory("\\");
    chdir(buffer);
    printf(" Press any key to quit...");
     getch();
     return;
  }
Exemple #3
0
void show_directory( const fs::path& dirpath )
{
    fs::directory_iterator itr( dirpath );
    fs::directory_iterator endItr;

    for ( ; itr != endItr; ++itr )
    {
        if ( fs::is_regular_file( itr->status() ) )
        {
            show_file( itr->path() );
        }
        else if ( fs::is_directory( itr->status() ) )
        {
            show_directory( itr->path() );
        }
    }
}
Exemple #4
0
int main( int argc, char* argv[] )
{
    // Get the file to examine
    std::string filename;

    if ( argc < 2 )
    {
        std::cerr << "Usage: ./filesystem [filepath]" << std::endl;
        return EXIT_FAILURE;
    }
    else
    {
        filename = argv[1];
    }

    // Create a boost path
    fs::path filepath( filename );

    // Does the file exist?
    if (! fs::exists(filepath) )
    {
        std::cerr << "File does not exist: " << filename << std::endl;
        return EXIT_FAILURE;
    }

    // Is this a file or a directory?
    if ( fs::is_regular_file( filepath ) )
    {
        show_file( filepath );
    }
    else if ( fs::is_directory( filepath ) ) 
    {
        show_directory( filepath );
    }

    return EXIT_SUCCESS;
}
int main(int argn ,char *argv[])
{	
	char in[100];
	while(1)
	{
		int n = strlen(para[0]);
		printf("%s->", para[0]);
		memset(in, 0, sizeof(in));
		gets(in);
		int choice = explain(in);
		//根据命令解释器的返回结果执行相对应的命令
		switch(choice)
		{
		case -1: printf("' %s '不是内部或外部命令,也不是可运行的程序\n或批处理文件。\n", in);break;
		case 0 : show_time();break; 
		case 1 : show_version();break;
		case 2 : show_date();break;
		case 3 : clrscr(0, 0);break;
		case 4 : show_directory();break;
		case 5 : help();break;
		case 6 : show_current_tree(para[0], 0);break;
		case 7 : return 0;
		case 8 : print_text(para[0]);break;	
		case 9 : if(del_dir(para[0]) == 0)	del_files(para[0]);break;//如果para[0]是文件夹,则执行删除文件夹函数,否则执行文件删除函数
		case 10 : creat_dir(para[0]);break;
		case 11 : rename_file(para[0], para[1]);break;
		case 12 : change_path(in);break;
		}//{"time", "version", "date", "cls", "dir", "help", "tree", "print", "del", "mkdir", "ren"};
		if(choice != 12)//如果没有改变路径,则每次都把当前工作目录下的以外的其它字符清除
		{
			memset(para[0] + n, 0, (100 - n) * sizeof(char));
			memset(para[1] + n, 0, (100 - n) * sizeof(char));
		}
	}
	return 0;
}
Exemple #6
0
void
set_directory(
    char *	dir,
    int		verbose)
{
    char *cmd = NULL;
    char *new_dir = NULL;
    char *qnew_dir;
    char *dp, *de;
    char *ldir = NULL;

    /* do nothing if "." */
    if(strcmp(dir,".")==0) {
	show_directory();		/* say where we are */
	return;
	/*NOTREACHED*/
    }

    if (disk_name == NULL) {
	g_printf(_("Must select disk before setting directory\n"));
	return;
	/*NOTREACHED*/
    }

    ldir = stralloc(dir);
    clean_pathname(ldir);

    /* convert directory into absolute path relative to disk mount point */
    if (ldir[0] == '/')
    {
	/* absolute path specified, must start with mount point */
	if (strcmp(mount_point, "/") == 0)
	{
	    new_dir = stralloc(ldir);
	}
	else
	{
	    if (strncmp(mount_point, ldir, strlen(mount_point)) != 0)
	    {
		g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
		       mount_point);
		amfree(ldir);
		return;
		/*NOTREACHED*/
	    }
	    new_dir = stralloc(ldir+strlen(mount_point));
	    if (strlen(new_dir) == 0) {
		new_dir = newstralloc(new_dir, "/");
					/* i.e. ldir == mount_point */
	    }
	}
    }
    else
    {
	new_dir = stralloc(disk_path);
	dp = ldir;
	/* strip any leading ..s */
	while (strncmp(dp, "../", 3) == 0)
	{
	    de = strrchr(new_dir, '/');	/* always at least 1 */
	    if (de == new_dir)
	    {
		/* at top of disk */
		*(de + 1) = '\0';
		dp = dp + 3;
	    }
	    else
	    {
		*de = '\0';
		dp = dp + 3;
	    }
	}
	if (strcmp(dp, "..") == 0) {
	    if (strcmp(new_dir, "/") == 0) {
		/* at top of disk */
		g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
		       mount_point);
		/*@ignore@*/
		amfree(new_dir);
		/*@end@*/
		amfree(ldir);
		return;
		/*NOTREACHED*/
	    }
	    de = strrchr(new_dir, '/');	/* always at least 1 */
	    if (de == new_dir)
	    {
		/* at top of disk */
		*(de+1) = '\0';
	    }
	    else
	    {
		*de = '\0';
 	    }
	} else {
	    /*@ignore@*/
	    if (strcmp(new_dir, "/") != 0) {
		strappend(new_dir, "/");
	    }
	    strappend(new_dir, ldir);
	    /*@end@*/
	}
    }

    qnew_dir = quote_string(new_dir);
    cmd = stralloc2("OISD ", qnew_dir);
    amfree(qnew_dir);
    if (exchange(cmd) == -1) {
	exit(1);
	/*NOTREACHED*/
    }
    amfree(cmd);

    if (server_happy())
    {
	disk_path = newstralloc(disk_path, new_dir);
	suck_dir_list_from_server();	/* get list of directory contents */
	if (verbose)
	    show_directory();		/* say where we moved to */
    }
    else
    {
	g_printf(_("Invalid directory - %s\n"), dir);
    }

    /*@ignore@*/
    amfree(new_dir);
    amfree(ldir);
    /*@end@*/
}