Auto grab files based on file name

3 visualizaciones (últimos 30 días)
Tyler
Tyler el 20 de Dic. de 2022
Respondida: cui,xingxing el 21 de Dic. de 2022
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

Respuestas (1)

cui,xingxing
cui,xingxing el 21 de Dic. de 2022
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.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by