I have a html table which shows all the files present in a local directory.
There is a remove button which deletes corresponding row of the table. Below is the code for that:
$(document).ready(function(){
$("#myTable").on('click','.btnDelete',function(){
$(this).closest('tr').remove();
});
});
<td><button type='button' class='btnDelete'>x</button></td>
But this button only removes the row from the table and as I refresh my page, it again shows that file because its still there in the working directory.
What I want is to delete file from directory itself. So that next time when I refresh my webpage, it will not show that file again.
Is this possible to achieve this? Can I delete a file from my local directory using html button? If yes, please suggest how.
P.S. Below is the code which I used to create the table:
<table id="myTable" style="width:100%">
<tr>
<th>Select One</th>
<th>File Name</th>
<th>File Size</th>
<th>File Type</th>
<th>Remove</th>
</tr>
{% for file in files %}
<tr>
<td><input type="radio" name="myRadio" id="data"></td>
<td>
<a href="{{ (request.path + '/' if request.path != '/' else '') + file }}" id="data">
{{ file }}
</a>
</td>
<td>
fileSize
</td>
<td>
<p>pdf</p>
</td>
<td><button type='button' class='btnDelete'>x</button></td>
</tr>
{% endfor %}
</ul>
</table>
Edit 2: This is my working directory setup:
Files which I am showing in html table are under /uploads.
Simple HTML/Javascript webpage page cannot delete files from the computer. Just imagine the havoc it could create if you'd visit a webpage and it deleted files from your computer...
However if you run a webserver with phpor nodejs on the same machine, than it can be done.
If your objective simply hide file from the table, you could store the list of "deleted" files in localstorage and in the code that generates the table check each file against localstorage database. I'm not familiar with the type of template you are using, so can't really show you an example