I have a recursive delete stored procedure that removes all files and folders from my records when I delete a file or folder. However, I also have a file directory where the actual files are stored. These file names are stored in the records that are to be deleted. How would I manage retrieving the filename from the record about to be deleted and deleting that file from the directory as well?
Here is my procedure as it stands:
WHILE (SELECT COUNT(FileID) FROM Files WHERE ParentFolderID is not null AND ParentFolderID not in (SELECT FileID FROM Files) AND ParentfolderID !=0 ) > 0
BEGIN
DELETE FROM Files Where ParentFolderID is not null AND ParentFolderID !=0 AND ParentFolderID not in (SELECT FileID FROM Files);
END
The identifier in Files used in retrieving a file from the directory is "FileName". Long story short, while deleting "X" from Files, get filename of "X" and delete from file directory too.