0
del /q "C:\Users\John Cena\Desktop\YT\*"

I am creating a batch file. The above command permanently deletes all the files of a particular folder. But I don't want to delete the files permanently. I am looking for an alternative of "del" command which will help me to delete the files to recycle bin so that if I need any deleted file I can restore that from recycle bin.

1
  • Normally a batch file should know that files can be permanently deleted. Try solution 2 in the article below to move to recycle bin: codeproject.com/Questions/520260/… – John Nov 16 '19 at 16:17
1

This is not possible using the del command.

You could use PowerShell for that.

You need first to start the PowerShell command prompt as Administrator and run the following:

Install-Module -Name Recycle

From now of you may include the following line in any batch file, without the need to run as Administrator:

powershell "Remove-ItemSafely 'C:\Users\John Cena\Desktop\YT\*'" -Force

The parameter -Force is to avoid the prompt for permission to delete.

2
  • The user who will run the batch file will not have administrative privilege. – macX Tutorials Nov 17 '19 at 2:59
  • Admin permissions are only required once during the installation of the Recycle module. Its subsequent usage does not require any special permissions. – harrymc Nov 17 '19 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.