I have 10 excel files, i want the name of each excel file.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have 10 excel files, i want the name of each excel file.
Thanks in advance
0 Kommentare
Antworten (1)
Walter Roberson
am 20 Nov. 2016
%code to find all excel files in a directory
%warning: this code makes no attempt to verify that xml files were produced by Excel
excel_extn = {'xlc', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xlw', 'xml' };
projectdir = 'C:\Where\Your\Files\Are';
num_extn = length(excel_extn);
dinfo = cell(num_extn, 1);
for K = 1 : num_extn
dinfo{K} = dir( fullfile( projectdir, ['*.', excel_extn{K}]);
end
dinfo = vertcat(dinfo{:});
excel_file_names = fullfile( projectdir, {dinfo.name} );
In the special case where only a single excel extension is to be handled, this code could be much shorter.
3 Kommentare
Walter Roberson
am 20 Nov. 2016
projectdir = 'C:\Where\Your\Files\Are';
dinfo = dir( fullfile(projectdir, '*.xls') );
excel_file_names = {dinfo.name};
Be sure to update projectdir to the appropriate directory name.
In the case of wanting to find the files in the current directory:
dinfo = dir( '*.xls' );
excel_file_names = {dinfo.name};
You can cross-check with
ls('*.xls')
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!