Search multiple image in a folder

9 Ansichten (letzte 30 Tage)
monika roopak
monika roopak am 25 Jul. 2022
Beantwortet: Siraj am 13 Sep. 2023
I have folder of over 10,000 images, I need to search specific mulitple images by filename (such as 1.jpg, 15.jpg )and save all those images into another folder.
Could anyone please suggest how to code for this.
  4 Kommentare
Rik
Rik am 26 Jul. 2022
You can use dir to find all files, then use fullfile and movefile (or copyfile) in a loop.
Jan
Jan am 28 Jul. 2022
@monika roopak: If you want to get help, do not let the readers guess the details of your problem.
How is your list stored? As table, cell string, string array or vector containing the numerical indices? What does "which I want to search" mean?
The code will have about 4 or 5 lines only and is typed in 20 seconds, but currently this would include too much guessing of what you exactly need. See: How to ask a good question

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Siraj
Siraj am 13 Sep. 2023
Hi! It is my understanding that you intend to choose specific files from a source folder and transfer them to another destination folder. The filenames of these specific files are stored in a list, and you want to move only these files.
To accomplish this task, you can iterate through the files in the source folder and determine whether each file should be moved or not. If a file is meant to be moved to the destination folder, you can utilize the "movefile" function to perform the actual file transfer. To obtain a list of all files in the source folder, the "dir" function can be used. To check if a filename exists in the list of files to be moved, you can employ the "ismember" function. For a clearer understanding, please refer to the provided code example and accompanying screenshots.
%path to source folder
sourceFolder = 'SourceFolder';
%path to destination folder
destinationFolder = 'DestinationFolder';
%looking up for all the files present in the SourceFolder
fileList = dir(fullfile(sourceFolder, '*.txt')); % Replace '*.txt' with the desired file extension or pattern
List_of_files_to_move = {'File1.txt', 'File4.txt'};
for i = 1:numel(fileList)
fileName = fileList(i).name;
% if this file, is one of the file that is to be moved.
if (ismember(fileName, List_of_files_to_move))
sourceFile = fullfile(sourceFolder, fileName);
destinationFile = fullfile(destinationFolder, fileName);
movefile(sourceFile, destinationFile);
end
end
Folder contents before executing the above code
Folder contents after executing the above code.
For more information on the "movefile", "dir", and "ismember" functions, you can refer to the following links:
These resources will provide you with detailed explanations and examples of how to use these functions effectively.
Hope this helps.

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by