i want to delete any file and folder parmanently in my hard disk
sometime when we delete any file and folder. after using a data recovery software
they will be recover and come back .but i want to do something so the files cannot recover after using any data recovery software.
just i want to remove a file parmmanently to our hard disk

See if this helps :

API Declare :

Option Explicit

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
 
Private Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Long
    hNameMappings As Long
    lpszProgressTitle As Long
End Type
 
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SILENT = &H4

Private Sub ShellDeleteOne(sFile As String)
 
  'set some working variables
   Dim shf As SHFILEOPSTRUCT
 
  'terminate the file string with
  'a pair of null charss
   sFile = sFile & vbNullChar & vbNullChar
 
  'set up the SHFile options
   With shf
      .wFunc = FO_DELETE  'action to perform
      .pFrom = sFile      'the file to act on
      .fFlags = 0& ' Delete permanent
      .fFlags = .fFlags + FOF_NOCONFIRMATION ' No confirm to delete
      .fFlags = .fFlags + FOF_SILENT
   End With
 
  'perform the delete
   Call SHFileOperation(shf)

End Sub

Delete File :

Private Sub Command1_Click()
    Call ShellDeleteOne("D:\junk.txt")
End Sub

Delete Folder :

Private Sub Command1_Click()
    Call ShellDeleteOne("D:\junk")
End Sub

Delete All Files (folders n files) in folder junk

Private Sub Command1_Click()
    Call ShellDeleteOne("D:\junk\*.*")
End Sub

Edited 4 Years Ago by Jx_Man: Add some comments

Comments
Working correctly.. Thanks..

Hello I hope you are fine
the code is work just explain are you sure
The file parmanantly deleted to my hard disk
Thanks

This question has already been answered. Start a new discussion instead.