How to Open a Folder
Show older comments
Hey.
I need help trying to open a folder on matlab while the code is running. I want the folder to open as a response to the user clicking on the screen. I already have the folder in the same pathway as the overall code, I'm just having trouble with the syntax and general terminology to open a specfic folder.
11 Comments
Jan
on 11 Apr 2021
Please explain what you call "open a folder"? Do you want to access its contents by using fopen, or do you want to show it in a file explorer, e.g. the Windows Explorer?
Ghina Alhunaidi
on 11 Apr 2021
Jan
on 11 Apr 2021
I still cannot guess, what "access it's contents" means...
Ghina Alhunaidi
on 11 Apr 2021
Walter Roberson
on 11 Apr 2021
project = 'PuzzleOne';
dinfo = dir(project);
filenames = fullfile(project, {dinfo.name});
It is not clear what "to open a folder on matlab" means. Perhaps one of these might help you:
Jan
on 12 Apr 2021
@Ghina Alhunaidi: Remember, that the readers do not have the faintest idea about what you want to achieve. So explain it to us as if we were rubber ducks.
"basically they are gonna press on the screen" - who is "they" and what is "pressing on the screen"?! Do you mean: push a button in a GUI?
"and I want a folder to pop up and open without them having to open the folder manually" - "pressing on a screen" sounds like a manual opening.
A folder is a abstract construction for the organization of files. I'm sure you mean something very specific when you say "a folder pops up". So please explain explicitly, what this is. A window of the Windows Explorer? A dialog for choosing files like uigetfile? The output of dir in the command window?
Ghina Alhunaidi
on 12 Apr 2021
Stephen23
on 12 Apr 2021
"Is it possible to do that, have matlab open the selected file?"
What does "open the selected file" mean exactly: open the file using its default application on your OS? Or open the file using some other non-default application on your OS? Or open the file as text within the MATLAB editor? Or do you want to actually import the file data using a suitable importing tool/function for that file format, so that you can perform further processing of the file data within MATLAB?
The more accurately you describe what you want, the easier it is for us to help you.
Ghina Alhunaidi
on 12 Apr 2021
Walter Roberson
on 12 Apr 2021
[filename,filepath] = uigetfile('*.mov');
if isempty(filename)
%user cancel, handle appropriately here
end
fullname = fullfile(filepath, filename);
open(fullname)
Using path as the name of a variable is not recommended as path controls the MATLAB search path.
Answers (1)
Maybe you want to open a file inside this folder?
function main
myPath = fileparts(mfilename('fullpath')); % Folder of this M-file
Folder = fullfile(myPath, 'NameOfSubfolder'); % Subfolder inside
Data = load(fullfile(Folder, 'YourData.mat')); % A specific file there
...
end
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
