how to delete file in a folder from a datapath on mysql table?

i have codes to delete a file information, like id, name, location(the folderpath), and date. it will be deleted from the the table but the file will still exist in the folder. how to delete the file too when we delete its information from mysql table? here is the codes:
function deletebtn_Callback(hObject, eventdata, handles)
choice = questdlg('Do you really want to delete this data?', ...
'Confirm Delete', ...
'Yes','No','Yes');
x=char(get(handles.txtid,'string'));
conn=database('database','root','','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/');
sqlquery = ['delete from iris_table where id = ''' x ''''];
switch choice
case 'Yes'
curs = exec(conn,sqlquery);
fetch(curs);
exec(conn, 'rollback');
exec(conn, 'commit');
[ mydata,header,no ] = buka()
set(handles.Tabel,'data',mydata,'ColumnName',header,'RowName',no);
set(handles.Tabel,'Data',mydata);
msgbox('Deleted','Success','warn');
skripsi=guidata(gcbo);
set(skripsi.txtid,'string','');
set(skripsi.txtname,'string','');
set(skripsi.txtlocation,'string','');
set(handles.deletebtn,'Enable','off');
set(handles.editbtn,'Enable','off');
set(handles.txtdate,'String',(datestr(date, 'yyyy-mm-dd')));
cla(handles.axes1);
confirm = 1;
case 'No'
confirm = 0;
end

Answers (1)

All you need is a delete() command with the file name. Unfortunately it is not clear, where the file name is stored. Perhaps you have to request it at first from your database.

3 Comments

the filename is displayed on text box. i imported mysql table to matlab, when you click a row in the table, every data in every column on that row will be also displayed on text boxes. like id, name, location(data path), and date(the date when the data saved). and when i push delete button it will delete the selected data from database. can we delete the file in the folder based on its filepath instead?
As I said already: Yes. All you need is the delete command and the file names. I does not wllow me to post some code, if you mention, that the file names are dispalyed anywhere, because I still do not know where they are displayed or even better, how they can be obtained as a variable directly.
You have to get a list of the file names as cell string. Then:
for iFile = 1:numel(FileList)
delete(FileList{iFile});
end
But how this FileList can be obtained is something I cannot guess, so if you cannot do this by your own, please provide any useful details. The shown code does something else and the descriptions do not explain the needed detail yet.
ya ok thanks, have a nice day sir.

Sign in to comment.

Asked:

on 19 Jun 2017

Commented:

on 20 Jun 2017

Community Treasure Hunt

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

Start Hunting!