how to delete file in a folder from a datapath on mysql table?
Show older comments
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)
Jan
on 20 Jun 2017
0 votes
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
Jan
on 20 Jun 2017
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.
Glenn
on 20 Jun 2017
Categories
Find more on Database Toolbox 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!