int main (int argc, char ** argv) { open_FS(); printf ("\nREPETOIRE AVANT :\n"); list_dir (); printf ("FAT AVANT : "); list_fat (); printf ("\nEFFACER %s \n", argv[1]); if (delete_file (argv[1]) ) printf ("%s n'existe pas \n", argv[1]); else { printf ("\nREPETOIRE APRES :\n"); list_dir (); printf ("FAT APRES : "); list_fat (); } close_FS (); return EXIT_SUCCESS; }
int main(int argc, char **argv) { if (argc > 1) list_dir(argv[1]); else list_dir("."); return 0; }
int main( int argc, char *argv[] ) { if( argc <= 1 ) list_dir( "." ); else { int i; for( i = 1; i < argc; ++i ) list_dir( argv[i] ); } return EXIT_SUCCESS; }
// ls => ls <cwd> // ls dir => ls <cwd>/dir // ls a/b/c // ls a/b/c e/f/g /h/i/j int my_ls(int argc, char* argv[]) { result_t result = NONE; const int device = running->cwd->device; // If given no path, ls cwd if(argc < 2) { list_dir(running->cwd); return SUCCESS; } // ls each path given by user int i = 1; while(i < argc) { int ino = getino(device, argv[i]); MINODE* mip = iget(device, ino); if(!mip) { result = DOES_NOT_EXIST; printf("ls: cannot access '%s':" " No such file or directory\n", argv[i]); goto clean_up; } // If printing multiple lists label each one if(argc > 2) printf("%s:\n", argv[i]); if(S_ISDIR(mip->inode.i_mode)) list_dir(mip); else list_file(mip, argv[i]); clean_up: // Move parent inode from memory to disk iput(mip); if(result != NONE) return result; i++; } return SUCCESS; }
int main(int argc, char *argv[]) { DIR *d1; struct dirent *dir; char *filename; d1 = opendir("."); if(argc != 2) { perror("Please enter search string\n"); exit(0); } if (d1) { while ((dir = readdir(d1)) != NULL) { filename = dir->d_name; if (dir->d_type & DT_DIR){ if (strcmp(filename,"..") & strcmp(filename,".")) { //~ printf("%s\n",filename); list_dir(filename, argv[1]); } } //reader(filename,argv[1],dir,"/"); } closedir(d1); } return(0); }
static void get_theme_names(GPtrArray* names) { void add_themes_from_dir(GPtrArray* names, const char* dir) { if (access(dir, F_OK) != 0) return; GPtrArray* list = list_dir((guchar*)dir); g_return_if_fail(list != NULL); int i; for (i = 0; i < list->len; i++){ char* index_path = g_build_filename(dir, list->pdata[i], "index.theme", NULL); if (access(index_path, F_OK) == 0){ g_ptr_array_add(names, list->pdata[i]); } else g_free(list->pdata[i]); g_free(index_path); } g_ptr_array_free(list, TRUE); } gint n_dirs = 0; gchar** theme_dirs = NULL; gtk_icon_theme_get_search_path(icon_theme, &theme_dirs, &n_dirs); // dir list is derived from XDG_DATA_DIRS int i; for (i = 0; i < n_dirs; i++) add_themes_from_dir(names, theme_dirs[i]); g_strfreev(theme_dirs); g_ptr_array_sort(names, strcmp2); }
int main(int argc, char **argv) { int i = 0; if ( 1 == argc ) { return (list_dir(".")); } for (i = 0; i < argc - 1; i++) { fprintf(stdout, "\n%s:\n", argv[i + 1]); list_dir(argv[i + 1]); } return 0; }
samrpc_result_t * samrpc_list_dir_4_svr( file_restrictions_arg_t *arg, struct svc_req *req /* ARGSUSED */ ) { int ret = -1; sqm_lst_t *lst = NULL; Trace(TR_DEBUG, "List dir max[%d], filepath[%s], restrictions[%s]", arg->maxentries, arg->filepath, arg->restrictions); /* free previous result */ xdr_free(xdr_samrpc_result_t, (char *)&rpc_result); SAMRPC_CHECK_TIMESTAMP(arg->ctx->handle->timestamp); Trace(TR_DEBUG, "Calling native library to list dir"); ret = list_dir( arg->ctx, arg->maxentries, arg->filepath, arg->restrictions, &lst); SAMRPC_SET_RESULT(ret, SAM_STRING_LIST, lst); Trace(TR_DEBUG, "List dir files return [%d] with [%d] entries", ret, (lst != NULL) ? lst->length : -1); return (&rpc_result); }
int ft_max_majmin(char *folder, const char **args, int mode, int i) { char **array; struct stat info; long int size; int len; int mlen; mlen = 0; array = list_dir(args, array_size((char **)args), folder); array = ft_qsort(array, array_size(array)); if (ft_strchr(ft_get_flags(args), 't') != NULL) array = ft_sort_by_time(array, array_size(array), folder); while (lstat(array[i], &info) != -1) { if ((len = 0) == 0 && mode == 1) size = (long)major(info.st_rdev); else size = (long)minor(info.st_rdev); while ((size = (size / 10)) != 0) len++; if (is_dot(array[i], folder, args) && len > mlen) mlen = len; i++; } return (mlen + 1); }
int main(int argc, char *argv[]) { //Usage clause: //Expecting one command line argument, a directory name if(argc != 2) { printf("usage: %s <directory>\n",argv[0]); } //variables struct stat statS; //recursively searches for a core file, prints its location and removes it stat(argv[1],&statS); if(S_ISDIR(statS.st_mode)) { //recursively gets and prints the information out of the contents of the directory that have the name of core list_dir(argv[1],0); } else { printf("The command line argument was not a directory\n"); } printf("\n"); return 0; }
//THIS FUNCTION ADD A WATCH TO ALL DIRECTORIES AND SUBDIRECTORIES //THAT ARE ALREADY WRITTEN void list_dir(String dir_to_read, int fd, int wds[], String dirs[], int counter){ struct dirent *de; DIR *dr = opendir(dir_to_read); if (dr == NULL){ syslog(LOG_INFO, "FileTransaction: Could not open current directory"); } while ((de = readdir(dr)) != NULL){ struct stat s; String subdir = ""; sprintf(subdir, "%s/%s", dir_to_read, de->d_name); stat(subdir, &s); if (S_ISDIR(s.st_mode)){ if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { int wd = inotify_add_watch(fd, subdir, IN_ALL_EVENTS); wds[counter] = wd; strcpy(dirs[counter], subdir); counter++; if (wd == -1){ }else{ syslog(LOG_INFO, "FileTransaction: READ := Watching:: %s\n", subdir); } list_dir(subdir,fd, wds, dirs, counter); } } } closedir(dr); }
void ls_core(t_d *d, char *path) { t_list_ls *list; t_list_ls *lst_deb; char *test; list = NULL; ls_core2(d); lst_deb = list_dir(list, d, path, NULL); if (d->denied == 0) display_choose(lst_deb, d, path); else return (ls_core3(d, lst_deb)); d->nb_display = 1; list = lst_deb; while (list != NULL && d->tab_option[2] == 1) { if (list->c_type == 'd' && ft_strcmp("..", list->name) != 0 && ft_strcmp(".", list->name) != 0) { test = ft_strdup(list->path); ls_core(d, test); free(test); } list = list->next; } free_element(lst_deb); }
int main(int argc, char *argv[]){ struct stat *buf = NULL; char *ptr = NULL; int size; ptr = (char *)malloc(100 * sizeof(char)); if(ptr == NULL){ printf("ptr malloc failed\n"); exit(1); } buf = (struct stat *)malloc(sizeof(struct stat)); if(buf == NULL){ printf("buf malloc failed\n"); exit(1); } if(!getcwd(ptr, size)){ printf("getcwd failed\n"); exit(1); } list_dir(ptr, buf); free(ptr); free(buf); ptr = NULL; buf = NULL; return 0; }
/* ---------------------------------------------------------- * ls: * driver for ls */ void ls(char** args, int numArgs) { int i=0; if(numArgs ==0) { list_dir(0); } // if >1 arguments are passed on, do ls for each for(i=0; i<numArgs; i++) { list_dir(args[i]); if(i<numArgs-1) printf("\n\n"); } }
char * list(gfarm_stringlist *paths, gfs_glob_t *types, int *need_newline) { char *e, *e_save = NULL; gfarm_stringlist dirs, files; int i, nfiles, ndirs; if (option_directory_itself) { return (list_files("", gfarm_stringlist_length(paths), GFARM_STRINGLIST_STRARRAY(*paths), need_newline)); } e = gfarm_stringlist_init(&dirs); if (e != NULL) { fprintf(stderr, "%s: %s\n", program_name, e); return (e); } e = gfarm_stringlist_init(&files); if (e != NULL) { fprintf(stderr, "%s: %s\n", program_name, e); gfarm_stringlist_free(&dirs); return (e); } for (i = 0; i < gfarm_stringlist_length(paths); i++) { char *path = gfarm_stringlist_elem(paths, i); if (gfs_glob_elem(types, i) == GFS_DT_DIR) gfarm_stringlist_add(&dirs, path); else gfarm_stringlist_add(&files, path); } nfiles = gfarm_stringlist_length(&files); ndirs = gfarm_stringlist_length(&dirs); if (nfiles > 0) { e = list_files("", nfiles, GFARM_STRINGLIST_STRARRAY(files), need_newline); /* warning is already printed in list_files() */ if (e_save == NULL) e_save = e; } gfarm_stringlist_free(&files); if (nfiles == 0 && ndirs == 1) { e = list_dir("", gfarm_stringlist_elem(&dirs, 0), need_newline); /* warning is already printed in list_dir() */ } else { e = list_dirs("", ndirs, GFARM_STRINGLIST_STRARRAY(dirs), need_newline); /* warning is already printed in list_dirs() */ } if (e_save == NULL) e_save = e; gfarm_stringlist_free(&dirs); return (e_save); }
/** * read_folder - Reads a folder and subfolders * @path: Path to folder * Description: Puts all files/folders to an ntree */ NTree *read_folder(const char *path) { NTree *tree; int len; for (len=0; path[len]; len++); ntree_insert(&tree, NULL, (char *)path); list_dir ((char *)path, len, &tree); return tree; }
int main (int argc, char ** argv) { open_FS(); list_dir (); close_FS (); return EXIT_SUCCESS; }
/* * driver.c */ int main(int argc, char* argv[]) { //char input_file[100]; //strcpy(input_file,argv[1]); //wave_Read(input_file); // call the wave_Read() function int i,j; int num_files; int num_tracks; //double percentage_matching; char path[100]; char path_temp[100]; printf("Enter path of folder:\n"); scanf("%s",path); strcpy(path_temp,path); FILE *f=fopen("input1.txt","w+"); num_files = noof_files(path); fprintf(f,"%d",num_files); list_dir(f,path); fclose(f); FILE *fp = fopen("input1.txt","r+"); fscanf(fp,"%d", &num_tracks); char track_names[num_tracks][20]; char track_txt[num_tracks][20]; //printf("Enter track names:\n"); for(i=0;i<num_tracks;i++) { fscanf(fp,"%s", track_names[i]); } fclose(fp); for(i=0;i<num_tracks;i++) { //sprintf(track_txt[i],"track%d.txt",i+1); strcpy(track_txt[i], trim_wav(track_names[i])); printf("%s %s\n", track_names[i], track_txt[i]); wave_Read(track_names[i],track_txt[i]); } return 0; }
//Name: list_dir //Parameters: name of the directory and the level (int) //Description: prints out the contents of a directory recursively that is removed(core files) void list_dir(char * name, int level) { DIR *dir; struct dirent *entry; struct stat statS; int offset = level*2; int error; int flag = 0; //Opens the directory if (!(dir = opendir(name))) { return; } //make the current directory the one that is passed chdir(name); //if its a directory //it calls list_dir for that directory while((entry = readdir(dir)) !=NULL) { if(lstat(entry->d_name,&statS)==-1) { perror("Stat"); } //checks to see if the entry is a directory if(S_ISDIR(statS.st_mode)) { //skips over "." and ".." if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } printf("%*s%s/\n",offset,"",entry->d_name); list_dir(entry->d_name,level+1); } //if it's not a directory its a file,looks to see if it is a core file, prints the location and removes it else { if(strcmp("core",entry->d_name) == 0) { printf("%*sremoved: %s%20d bytes\n",offset,"",entry->d_name,(int)statS.st_size); unlink(entry->d_name); flag = 1; } } } if(flag == 0) { printf("%*sNo cores found in this directory\n",offset,""); } //change the directory back to its parent chdir(".."); closedir(dir); }
/** * Program entry point. * @param argc number of args * @param list of arguments * @return exit code */ int main(int argc, char*argv[]) { char **filenames; int count = list_dir(".", &filenames); for(int i = 0; i < count; ++i) { puts(filenames[i]); free(filenames[i]); } free(filenames); }
int main (int argc, char ** argv) { open_FS(); printf ("\nREPETOIRE AVANT:\n"); list_dir (); if (mv_file (argv[1], argv[2])) printf ("%s n'existe pas\n", argv[1]); else { printf ("\nREPETOIRE APRES :\n"); list_dir (); } close_FS (); return EXIT_SUCCESS; }
int main(int argc, char *argv[]){ sHelper sHelp; uid_t p_runner = getuid(); sHelp.drop_priv_temp(p_runner); if(argc > 1){ std::cout << "This command takes no arguments. Please run as '$ showqueue'." << std::endl; }else{ list_dir(SPOOL, p_runner); } return 0; }
static void _pp_samba_get_devices_thread (GSimpleAsyncResult *res, GObject *object, GCancellable *cancellable) { static GMutex mutex; SMBData *data; SMBCCTX *smb_context; gchar *dirname; gchar *path; gchar *hostname = NULL; data = g_simple_async_result_get_op_res_gpointer (res); data->devices = g_new0 (PpDevicesList, 1); data->devices->devices = NULL; data->samba = PP_SAMBA (object); g_mutex_lock (&mutex); smb_context = smbc_new_context (); if (smb_context) { if (smbc_init_context (smb_context)) { smbc_setOptionUserData (smb_context, data); g_object_get (object, "hostname", &hostname, NULL); if (hostname != NULL) { dirname = g_strdup_printf ("smb://%s", hostname); path = g_strdup_printf ("//%s", hostname); g_free (hostname); } else { dirname = g_strdup_printf ("smb://"); path = g_strdup_printf ("//"); } smbc_setFunctionAuthDataWithContext (smb_context, anonymous_auth_fn); list_dir (smb_context, dirname, path, cancellable, data); g_free (dirname); g_free (path); } smbc_free_context (smb_context, 1); } g_mutex_unlock (&mutex); }
int main(int argc, char **argv) { char *initial_dir; if (argc == 1) initial_dir = (char *) get_current_dir_name (); else initial_dir = strdup (argv[1]); list_dir(initial_dir); return EXIT_SUCCESS; }
int main() { printf("Content-Type:application/text\n\n"); char *line=malloc(1); size_t s=1; getline(&line,&s,stdin); DIR_ROOT=strdup(line); list_dir(DIR_ROOT); //list_dir("/srv/www/kundaje/leepc12/atac"); return 1; }
int main (int argc, char *argv[]) { bool success = true; bool verbose = false; if (argc > 1 && !strcmp (argv[1], "-l")) { verbose = true; argv++; argc--; } if (argc <= 1) success = list_dir (".", verbose); else { int i; for (i = 1; i < argc; i++) if (!list_dir (argv[i], verbose)) success = false; } return success ? EXIT_SUCCESS : EXIT_FAILURE; }
static int list_dir(const string& path, const FileRecord& rec, const vector<string>& excludes, vector<FileRecord>* more) { int err; string full = path_append(rec.sourceBase, rec.sourceName); full = path_append(full, path); DIR *d = opendir(full.c_str()); if (d == NULL) { return errno; } vector<string> dirs; struct dirent *ent; while (NULL != (ent = readdir(d))) { if (0 == strcmp(".", ent->d_name) || 0 == strcmp("..", ent->d_name)) { continue; } if (matches_excludes(ent->d_name, excludes)) { continue; } string entry = path_append(path, ent->d_name); #ifdef HAVE_DIRENT_D_TYPE bool is_directory = (ent->d_type == DT_DIR); #else // If dirent.d_type is missing, then use stat instead struct stat stat_buf; stat(entry.c_str(), &stat_buf); bool is_directory = S_ISDIR(stat_buf.st_mode); #endif add_more(entry, is_directory, rec, more); if (is_directory) { dirs.push_back(entry); } } closedir(d); for (vector<string>::iterator it=dirs.begin(); it!=dirs.end(); it++) { list_dir(*it, rec, excludes, more); } return 0; }
int main(int argc, char *argv[]) { if(argc > 1) { struct stat statbuf; lstat(argv[1], &statbuf); if(!S_ISDIR(statbuf.st_mode)) { printf("it is not dir\n"); return -1; } list_dir(argv[1]); printf("total_lines:%u\n", total_lines); } else printf("please input dir\n"); return 0; }
void list_dir( char *directory, int depth ) { char path[512]; int dir = dfs_dir_findfirst( directory, path ); do { pr_depth( depth ); printf( "%s\n", path ); if( FILETYPE( dir ) == FLAGS_DIR ) { list_dir( path, depth + 2 ); } } while( (dir = dfs_dir_findnext( path )) != FLAGS_EOF ); }
/*----------------------------------------------------------------------*/ static void showdirs(struct dnode **dn, int ndirs) { //printf("=== ls showdirs\n"); int i, nfiles; struct dnode **subdnp; #ifdef CONFIG_FEATURE_LS_RECURSIVE int dndirs; struct dnode **dnd; #endif if (dn == NULL || ndirs < 1) return; for (i = 0; i < ndirs; i++) { if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) { printf("\n%s:\n", dn[i]->fullname); } subdnp = list_dir(dn[i]->fullname); nfiles = countfiles(subdnp); if (nfiles > 0) { /* list all files at this level */ #ifdef CONFIG_FEATURE_LS_SORTFILES shellsort(subdnp, nfiles); #endif showfiles(subdnp, nfiles); #ifdef CONFIG_FEATURE_LS_RECURSIVE if (all_fmt & DISP_RECURSIVE) { /* recursive- list the sub-dirs */ dnd = splitdnarray(subdnp, nfiles, SPLIT_SUBDIR); dndirs = countsubdirs(subdnp, nfiles); if (dndirs > 0) { #ifdef CONFIG_FEATURE_LS_SORTFILES shellsort(dnd, dndirs); #endif showdirs(dnd, dndirs); free(dnd); /* free the array of dnode pointers to the dirs */ } } dfree(subdnp); /* free the dnodes and the fullname mem */ #endif } } }