Auto grab files based on file name

2 次查看(过去 30 天)
Tyler
Tyler 2022-12-20
回答: cui,xingxing 2022-12-21
The code below changes the raw file to txt file. However, I want to have the code auto grab the file named "2022-09-07_003_DR06 PRE-TEST_HORIZONTAL_NOM_" instead of a new dialog box opening up. I have files that are basically the same but named POST instead of PRE or VERTICAL instead of HORIZONTAL so if I can get it to auto grab based on naming then I can apply that to all the different types of files.
Something like '*PRE-TEST_VERTICAL*NOM.txt' works in a similar code but I can't get it to adjust to the code below,
% Loop through each file, copy it and give new extension: .txt
for i = 1:numel(fileList)
file = fullfile(directory, fileList(i).name);
[tempDir, tempFile] = fileparts(file);
status = copyfile(file, fullfile(tempDir, [tempFile, '.txt']));
end
% Enter the directory to search for newly created text files of the data
[file_list, path_n] = uigetfile('.txt','Grab the files you want to process','MultiSelect','on');
if iscell(file_list) == 0;
file_list = {file_list};
end
%Starts a figure that will hold until all files have been processed
figure
hold on
for i = 1:length(file_list)
filename = file_list{i};
data_in = readmatrix([path_n filename]);
%Grabbing only the frequency and SE values
x = data_in(:,1);
y = data_in(:,3);
end

回答(1 个)

cui,xingxing
cui,xingxing 2022-12-21
hi,
you can try use datastore or fileDatastore instead of uigetfile to get all your file names,then use "string" class methods to handle each your file names,match pattern ,find ,replace specification character is easy.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by