auto run and delete files from multiple subfolders
Show older comments
My question consist over three parts
Part 1
My current directory is
E:\meta data\new\data _thesis\NCEP\winds_speed
In winds_speed , there are 30 folders (for year) and inside of each of these 30 folders there are further 12 folders are present.
Inside each of 12 folders, there is sorted_lat_split_NCAR_NCEP.m which i want to run automatically?
Part 2:
In this directory
E:\meta data\new\data _thesis\NCEP\winds_speed
there are 30 folders and inside of each of these 30 folders there are 12 folders and inside of each 12 folder, there is a runmyfile.m file which i want to delete from each folder?
Part 3
In this directory
E:\meta data\new\data _thesis\NCEP\winds_speed
there are 30 folders and inside of each of these 30 folders there are 12 folders and inside of each 12 folder, there is a abc.txt file inside of each of 12 folder. I want to paste each abc.txt file from this folder to my current directory
I am on window 7 and using matlab 2013, how can this do??
7 Comments
per isakson
on 12 Apr 2016
Edited: per isakson
on 12 Apr 2016
- Is there really a space in data _thesis?
- Which of these folders are in the search path of Matlab?
- Are these m-files scripts of functions? If functions, do they have input and/or output arguments?
Muhammad Usman Saleem
on 12 Apr 2016
Edited: Muhammad Usman Saleem
on 12 Apr 2016
Muhammad Usman Saleem
on 12 Apr 2016
Muhammad Usman Saleem
on 14 Apr 2016
per isakson
on 15 Apr 2016
Edited: per isakson
on 15 Apr 2016
- "24 text files name with Output_00.txt to Output_23.txt"   The script, sorted_lat_split_NCAR_NCEP.m, which you uploaded creates 17 files named. output_0.txt, ..., output_16.txt. Note the single 0 in output_0.txt.
for x = 0 : 16
....
fId = fopen( sprintf( 'Output_%d.txt', x), 'w' ) ;
fprintf( fId, ' \t \t \r\n' ) ; % first line
fprintf( fId, '%.3f\t%.3f\t%.3f\r\n', data(:) ) ;
fclose( fId ) ;
end
- "gather output_00.txt of apr folder in each year (1985 to 2015)"   What do you exactly mean by gather? For instance, shall the the first line of each file be included? (Or is gather the name of the script, to be constructed?)
- What about the other output-files and the other months?
- The output-files don't contain any information on date and time

Muhammad Usman Saleem
on 15 Apr 2016
Edited: Muhammad Usman Saleem
on 15 Apr 2016
per isakson
on 15 Apr 2016
Edited: per isakson
on 15 Apr 2016
- "with name Output_00.txt"   Did you change the script, , sorted_lat_split_NCAR_NCEP.m, to output double zero, 00?
- "my code just extracts these files from original one"   the word, "original one", is new to me. Does "extracts" refer to the operation of the script, sorted_lat_split_NCAR_NCEP.m?
"(Here we have auto run our mat file. Alright!)"   No, because
- I don't know what "auto run mat file" means and I failed to find it in the Matlab documentation. (I very recently updated from R2013a.)
- I wasn't aware that you use mat-files to solve this task
I believe, I understand the folder tree you use for this task.
E:\meta data\new\data _thesis\NCEP\winds_speed
1985
jan
...
dec
...
2015
jan
...
dec
"I want to copy(move) output_00.txt file of each month of each year into a folder with name Output_00.txt."
- New sub-folders will be added to the root.
- However, I don't understand the copy part, since one folder can only contain one file named, output_00.txt.
E:\meta data\new\data _thesis\NCEP\winds_speed
Output_00.txt
...
Output_16.txt
"So that when i open this folder, instead of moving in batch"   What is "moving in batch"?
Accepted Answer
More Answers (1)
Image Analyst
on 12 Apr 2016
2 votes
Use genpath() to get a list of all files in all subfolders. See attached demo.
4 Comments
Muhammad Usman Saleem
on 12 Apr 2016
Edited: per isakson
on 13 Apr 2016
Image Analyst
on 12 Apr 2016
I don't know - it's not my code and you didn't give the complete error message so we don't know what line it's throwing the error on. Read this - it will help.
Muhammad Usman Saleem
on 13 Apr 2016
Edited: Muhammad Usman Saleem
on 13 Apr 2016
Muhammad Usman Saleem
on 16 Apr 2016
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!