how to select range of files

3 ビュー (過去 30 日間)
Ihaveaquest
Ihaveaquest 2023 年 1 月 5 日
コメント済み: Image Analyst 2023 年 1 月 5 日
prompt1 = '\nplease enter the starting serial number\n';
first_SN = input(prompt1);
prompt2 = '\nplease enter the ending serial number\n';
ending_SN = input(prompt2);
prompt3 = '\nplease enter the step size\n';
step = input(prompt3);
temp_directory = dir;
size(temp_directory)
class(first_SN)
b = 1;
a=first_SN;
while a <= ending_SN %%%builds list of serial numbers
SN{b}= num2str(a);
b = b+1;
a = a+step;
end
for c = 3:size(temp_directory)
temp_directory(c).name
isempty(strfind(SN, temp_directory(c).name)) % at this point is just copying the files from the temp dir
if isempty(strfind(SN, temp_directory(c).name)) ~= 1 % how my i have it just select the range of SN numbers
serial_number_folders(c).name = temp_directory(c).name;
end
end
end
  2 件のコメント
Fifteen12
Fifteen12 2023 年 1 月 5 日
What is your question? What is the purpose of your code?
Ihaveaquest
Ihaveaquest 2023 年 1 月 5 日
how may i have it just select the range of SN numbers if i have a list of SN00001 - SN10000
how can i set a range of SN50 to SN100

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2023 年 1 月 5 日
You need to parse your filename to get the serial number (string) into a number (double). Then you can use an if inside your for loop to skip numbers outside the range
for k = 1 : numFiles
thisFileName =
serialNumber = ParseFilename(thisFileName);
if serialNumber < minSerialNumber || serialNumber > maxSerialNumber
continue; % Skip this file.
end
% else process the file.
end
  3 件のコメント
Ihaveaquest
Ihaveaquest 2023 年 1 月 5 日
splitstr??
Image Analyst
Image Analyst 2023 年 1 月 5 日
Tell me what a typical file name is and tell me what characters in the filename represent the serial number. Or is the serial number inside the file, not a part of it's file name?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePortfolio Optimization and Asset Allocation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by