Filter löschen
Filter löschen

How to open current working directory if a certain folder doesn't exists in the directory?

3 Ansichten (letzte 30 Tage)
So here is my code on a pushbutton callback:
prompt = {'Enter Patient Name or ID:'};
title = 'Input';
num_lines = 1;
defaultans = {'Patient'};
answer = inputdlg(prompt,title,num_lines,defaultans);
handles.file = cellstr(answer{1});
%Creating a new folder by the name of Patient's name that user entered
folder = handles.file{1}
guidata(hObject, handles);
mkdir(folder);
By far its working fine, now in a different pushbutton callback I want to display an error if the folder of same name already exists
folder = handles.file{1}
if exist(folder,'dir')
winopen(folder);
else
winopen(pwd);
end
But it shows error : Reference to non-existent field 'file'. Please Help. Thanks in advance
  4 Kommentare

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam
Adam am 13 Jan. 2017
Bearbeitet: Adam am 13 Jan. 2017
if exist( folder, 'dir' )
will test if a folder exists or not on the file system. Judging by your attempts at it though I'm not sure that is what you are asking for since you are checking if it exists on handles or if it is a string cell.
  5 Kommentare
Adam
Adam am 13 Jan. 2017
The guidata needs to be after the code in which you assign 'file' to 'handles', not when you access it.
I don't understand how you can be getting the error only sometimes. Either 'file' is a field or it isn't unless you keep clearing it or doing different things each time you run it.
winopen( pwd )
should not care whether 'file' exists on handles or not.
Adam
Adam am 13 Jan. 2017
Then you must be doing something else in code you haven't shared as this error does not make sense.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by