How to ask the user how many file extensions to search for
Ältere Kommentare anzeigen
I currently have a script which find files in a folder with a matching string that the user inputs.
I also have code where the user enters the file extensions he wants the script to look for.
ext1 = inputdlg('Please enter file extension #1: **\*. ');
ext2 = inputdlg('Please enter file extension #2: **\*. ');
ext3 = inputdlg('Please enter file extension #3: **\*. ');
fileData = [dir(fullfile(fileLoc,char(ext1))); dir(fullfile(fileLoc,char(ext2))); dir(fullfile(fileLoc,char(ext3)))];
What I want to do instead of ask the user how many different file extensions he wants to look for and then ask for them accordingly.
(e.g. User inputs he wants to search for 5 different file extensions and the script asks for 5)
I'd like to do this instead of just hard-coding in how many file extensions he can search for.
Akzeptierte Antwort
Weitere Antworten (2)
Nom
am 13 Sep. 2019
2 Kommentare
Walter Roberson
am 13 Sep. 2019
So somehow ext is a character vector instead of a cell array of char.
As a general fix: after you have called
ext = inputdlg('Please enter file extensions separated by a comma:. Example: txt, csv, ogg: ');
add
ext = cellstr(ext);
Though you might have to check isempty() first.
Adam Danz
am 13 Sep. 2019
inputdlg should always return a cell array:
Where is the 'txt, pdf, docx' char array coming from? I can't be the output to inputdlg.
Nom
am 13 Sep. 2019
0 Stimmen
17 Kommentare
Nom
am 13 Sep. 2019
Adam Danz
am 13 Sep. 2019
Do you want to write a hyperlink to an excel file or do you want to write a hyperlink to the command window that, when selected, opens the excel file?
Nom
am 13 Sep. 2019
Nom
am 16 Sep. 2019
Adam Danz
am 16 Sep. 2019
Unfortunately I could not run all of your code because I don't have the value for "fil". I can suggestion some areas to look at.
xlswrite(outputFile,outputData);
As you can read here, the 2nd input to xlswrite() is a "two-dimensional numeric, character array, or string array, or, if each cell contains a single element, a cell array". It doesn't look like that is the case in your code.
fileDates(~finalFlag) num2cell(fileSizes(~finalFlag) ./1024)
I'm not sure what's happening here (above). it looks like you're horizontally concatenating two things that are different sizes.
I can't easily troubleshoot if I can't reproduce the problem so if you still need some help, makes sure we have code and data so that we can step through each line of your code.
Nom
am 16 Sep. 2019
Adam Danz
am 16 Sep. 2019
Ok, since this section below is what's causing the problem, could you run the code up to that point and then save all of the needed variables to a mat file, and then attach that file.
outputData = [{'Starting Path:' fileLoc ' ';
'Time to Execute:' [sprintf('%.2f',overallTime+overallTime2) 's'] ' ';
'File Count:' num2str(sum(~finalFlag)) ' ';
'Date' 'Size' 'File'};
%vvvvvvvvvvvvvvvvvvvv ERROR vvvvvvvvvvvvvvvvvvvvvvvv
fileDates(~finalFlag) num2cell(fileSizes(~finalFlag) ./1024)]; fullPaths(~finalFlag)];
%^^^^^^^^^^^^^^^^^^^^ ERROR ^^^^^^^^^^^^^^^^^^^^^^^
So I need
- fileLoc
- overallTime
- overallTime2
- fileFlag
That way I can run that section.
Nom
am 16 Sep. 2019
Walter Roberson
am 16 Sep. 2019
Why not just comment that line out?
Nom
am 16 Sep. 2019
Nom
am 16 Sep. 2019
Adam Danz
am 17 Sep. 2019
I'm not sure how that solved the error you were getting.
Notice at the end of this line you transpose the array.
fullPaths = strrep(fullPaths,fileLoc,'')'; % Remove the header path
% HERE ^
So when you comment that out, fullPaths remains as a row-cell-array.
That causes the error when you try to horizontally concatenate the bottom line below.
outputData = [{'Starting Path:' fileLoc ' ';
'Time to Execute:' [sprintf('%.2f',overallTime+overallTime2) 's'] ' ';
'File Count:' num2str(sum(finalFlag)) ' ';
'Date' 'Size (kb)' 'File'};
fileDates(finalFlag) num2cell(fileSizes(finalFlag) ./1024) fullPaths(finalFlag)];
%|___column array___| {______________Column array_________| |____Row array______|
Nom
am 17 Sep. 2019
Kategorien
Mehr zu Data Import and Export finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!