Grab a file without writting full name

4 views (last 30 days)
Paulo Correia
Paulo Correia on 19 Oct 2022
Commented: Kevin Holly on 20 Oct 2022
I want to grab a file that is always located in same folder that starts with the name "Target" and ends with ".hex" but in front of Target there is a version number that can change.
In the following line you can see I'm trying to use the " * " to pick up any file. But this doesn't work. Anyone can help me how to do this?
firmwareFile = [basePath{1} '..\binaries\Target*.hex'];

Answers (1)

Kevin Holly
Kevin Holly on 19 Oct 2022
Edited: Kevin Holly on 19 Oct 2022
Can you try this?
folder = [basePath{1},filesep,'binaries']; % I'm assuming this is the folder location
firmwareFiles = dir(fullfile(folder,'Target*.hex'))
  11 Comments
Paulo Correia
Paulo Correia on 20 Oct 2022
Hello, how do I check if thie firmwareFiles is empty or has more than one file to throw an error?
Kevin Holly
Kevin Holly on 20 Oct 2022
To detect if it is empty:
isempty(firmwareFiles)
To detect how many files were detected:
size(firmwareFiles,1)

Sign in to comment.

Categories

Find more on Package and Share Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!