Link to home
Start Free TrialLog in
Avatar of Gerhardpet
GerhardpetFlag for Canada

asked on

Batch file to delete all files and folders

I have this batch file that will delete all files in a folder but it does not delete the folders inside the BVDATA folder

del "E:\ProgramData\BusinessVision\bv_till\BVDATA\*.*" /F /Q

Open in new window


Can any one help? I want to delete all files and folders/files inside sub-folders using a batch file
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Program Data is a protected folder. Try the script with Run as Administrator.
Avatar of Gerhardpet

ASKER

@oBdA - That worked. Thanks!

The ProgramData folder is in the E drive so it is not protected.
If it is only deleting files and not folders type the command like this:
del "E:\ProgramData\BusinessVision\bv_till\BVDATA\*" /F /Q

Open in new window


I removed the *.* and changed it to just *
Give that a try, and run your command prompt as administrator.
Avatar of oBdA
oBdA

John Hurst,
"del" only deletes files in the folder specified. If a folder is specified, it will delete files inside that folder.
But it will not delete a folder, which is why two steps are required.

Gerhardpet,
another possibility, if you don't mind deleting the root folder -- which you might if there are special NTFS permissions on it, or if it's shared -- is this:
ECHO rd /s /q "E:\ProgramData\BusinessVision\bv_till\BVDATA\*.*"
md "E:\ProgramData\BusinessVision\bv_till\BVDATA

Open in new window