Removing files that match a pattern from files that are on local PC

4 views (last 30 days)
Hi all,
I'm having a dataset with 506 rows and 3 fields:
What I need to do is remove the rows that contain certain codes like: 0b5de248-e010-4e21-9d4e-2e5cc326c38a.
The rows that need to be removed are the ones that correspond with the image values of this folder:
I already tried this code that allows to read the files in folder processed\test to variable the Files.
% Specify the folder where the files live.
myFolder = 'C:\Users\jorri\OneDrive - Wageningen University & Research\02Thesis\Project_Thesis_JorritvanGils\data\images\Images_Jorrit\processed\test';
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg');
theFiles = dir(filePattern);
How can I use the codes of the images in my local folder to remove the corresponding rows in the dataset.
I hope I explained sufficient. Thanks for your help!
Jorrit
  2 Comments
Stephen23
Stephen23 on 9 Nov 2021
Edited: Stephen23 on 9 Nov 2021
"I'm having a dataset with 506 rows and 3 fields:"
Your screenshot shows a structure with only 1 row, 506 columns, and 3 fields:
Tip: getting Windows to show the file extensions makes working with files much easier:

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 9 Nov 2021
Edited: Stephen23 on 9 Nov 2021
Assuming that no filenames are substrings of other filenames (e.g. all have the same number of characters):
P = 'C:\Users\jorri\OneDrive - Wageningen University & Research\02Thesis\Project_Thesis_JorritvanGils\data\images\Images_Jorrit\processed\test';
S = dir(fullfile(P,'*.jpg'));
[~,N] = fileparts({S.name});
X = contains({dataset.image},N);
dataset(X) = []

More Answers (0)

Community Treasure Hunt

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

Start Hunting!