Topic: как удалить файл?

При удалении записи файла из базы данных не удаляется сам файл  в папке files.  Что делать?

Re: как удалить файл?

У меня такая же проблема.

Re: как удалить файл?

1 получите адрес файла
2 удалите файл по адресу
3 удалите саму запись

Re: как удалить файл?

Привет Konstruktor, MarkoS, Sibprogsistem,
Это то, что тебе надо?
Derek.

Post's attachments

Attachment icon filedelete.zip 387.59 kb, 300 downloads since 2020-06-10 

Re: как удалить файл?

Hi, Derek,
Unfortunately, it doesn't work for me for some reason.
If possible, let me know your e-mail to send you my project.
Thanks in advance.
tehnicka-knjiga@tech-center.com

Re: как удалить файл?

Hi, Derek,
Here is some more explanation on what I need.
I have a two files named "gallery" (for saving photos) and "storage" (for saving other formats, like a pdf, zip, etc).
Photos are stored as LinkFile; Copy to gallery; FieldName: photo.
Other formats are stored as LinkFile; Copy to storage; FieldName: savedfile.
This part seems to be OK.
And I already have a paths to these file in my TableGrid1, (please see an attached screenshot).
I want to delete the both saved files (in gallery and storage) related to the record from the DataGrid1 which should be deleted.
How to do that?
Is it possible with click on delete button by adding some code for the same event?

Post's attachments

Attachment icon 2020-06-13_15-22-04.png 14.83 kb, 126 downloads since 2020-06-13 

7 (edited by derek 2020-06-13 23:46:48)

Re: как удалить файл?

Hi MarkoS,
Please have a look at the attachment.
I have used your example (2 folders called 'gallery' and 'storage' with the files being copied as linkfiles to these locations).
1.  If you DELETE a record in the tablegrid, the corresponding linked files in the 'gallery' and 'storage' folders are also deleted.
2.  If you CHANGE the photo or savedfile, the script deletes the old photo from the 'gallery' folder and / or the old savedfile from the storage folder.
Step 2) isn't necessary but if you don't do it, you have photos and savedfiles that no longer relate to a record, so not ideal.
Regards,
Derek.

Post's attachments

Attachment icon filedelete2.zip 383.99 kb, 328 downloads since 2020-06-14 

8 (edited by MarkoS 2020-06-14 11:07:44)

Re: как удалить файл?

Hi, Derek,
I am very grateful for your efforts to help.
I tried your example and it works perfectly.
Now I need time to include it in my project and test it.
But knowing myself, it is very likely that I will make a some mistakes.
It would be very good if I could contact you directly.
In addition, I need to recreate a huge 25-year-old database that can only run with old Windows.  XP is last Windows that can run this database.
I am forced to keep one old PC just to run this database.
I hope there is a way to open this database and eventually turn it into an MVD.
Of course, I am willing to pay for that service.
More information on request.
Thanks again.

Re: как удалить файл?

Привет Маrkos,
Вероятно, лучше загружать проекты на Форум и позволить всем взглянуть - у других пользователей могут быть разные и часто лучшие идеи и предложения о том, как решать проблемы.
А также, если кто-то отсутствует в течение нескольких дней, то вы не ждете возвращения этого человека.
Derek.
.
It's probably better to upload projects to the Forum and let everyone have a look - other users may have different and often better ideas and suggestions about how to solve problems.
And also, if someone is away for a few days, then you are not waiting for this person to return.

Re: как удалить файл?

OK.
Thanks.

Re: как удалить файл?

А можно как то не удалять файл а переместить его в корзину?

Re: как удалить файл?

Landropa wrote:

А можно как то не удалять файл а переместить его в корзину?

Файлы удаляет ОС, поэтому по умолчанию они перемещаются в корзину.

Визуальное программирование: блог и телеграм-канал.

13 (edited by k245 2022-05-11 09:22:59)

Re: как удалить файл?

konstruktor wrote:

При удалении записи файла из базы данных не удаляется сам файл  в папке files.  Что делать?

Ничего не делать. Стандартная система хранения файлов позволяет один и тот же файл добавлять в разные записи БД. Поэтому, если вы физически удалите такой файл, то он станет недоступным в другой записи. Но, если у вас стоит проверка на уникальность, тогда удаляйте, конечно... Скриптом. Но тут свои нюансы. Например, если вы удаляете запись кнопкой с функцией "Удаление". Тогда в обработчике OnClick нужно запомнить путь к удаляемому файлу, а в обработчике onAfterClick удалить файл. Либо полностью написать скрипт удаления по схеме, предложенной sibprogsistem и не использовать функцию кнопки "Удаление". Вот только я бы рекомендовал удалять файл после удаления записи, так как возможно запись не удастся удалить из-за контроля целостности данных (наличия ссылок на неё без каскадного удаления)

Визуальное программирование: блог и телеграм-канал.

Re: как удалить файл?

k245 wrote:
Landropa wrote:

А можно как то не удалять файл а переместить его в корзину?

Файлы удаляет ОС, поэтому по умолчанию они перемещаются в корзину.

Да нет после команды DeleteFile() в корзине нет файлов.