Need to delete backup files?
I did! I had some adhoc
.bak files taking up many gigglebytes. I remoted onto the server to delete them but I lacked the permission to perform the delete.
For one horrible moment I thought I might need to contact the IT department.
Fortunately I found out about
xp_delete_file just in time.
This procedure only deletes certain types of files. You tell it which folder to look in, which file extension to look for, and the maximum date of the file (so it won't accidentally delete new files or non back up files.)
EXEC master.sys.xp_delete_file 0,'E:\Temp\','BAK','2017-08-15',0
The five parameters are:
File Type: 0 for backup files or 1 for report files.
Folder Path: The folder to delete files. The path must end with a backslash "".
File Extension: This could be
TRNor an empty string ('') if the files have no extension, etc.
Date: The maximum date for files to be deleted.
Subfolder: 0 to ignore subfolders or 1 to recursively delete files in subfolders.
To see available space use: