Is it possible to get the path of a file using uigetfile() ?

23 次查看(过去 30 天)
What I want to do is get the path of a file that user selects, lets say an image is in downloads folder (example: 'C:\Users\%UserName%\Downloads\image.png').
So when executing the script the path of file is saved in a string and showed in command window.
Right now I have no succes with the following, I'm I using the correct functions for this?
filepath = fileparts( uigetfile() );
disp(['This is the file path: ',filepath]);

采纳的回答

Walter Roberson
Walter Roberson 2022-6-23
[filename, filepath] = uigetfile();
if ~ischar(filename); return; end %user cancel
fullname = fullfile(filepath, filename);
fprintf('This is the file path: %s\n', fullname);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by