# Delete files and folder using bat file via schedule task

• ### General discussion

• Hi I have written this batch file running as schedule task to delete files and folder as listed below. Script runs and not deleting any of the files or folder.

@echo off
del /F /Q E:\Apple\*.*
del /F /Q E:\Pet\*.*
del /F /Q E:\Animal\*.*
del /F /Q E:\IT\*.*
del /F /Q E:\device\*.*
del /F /Q E:\equipment\*.*
exit

• Changed type Tuesday, November 7, 2017 10:20 PM
• Moved by Tuesday, November 7, 2017 10:20 PM This is not "search the Internet for me" forum
Wednesday, September 27, 2017 6:37 AM

### All replies

• Hi,

Use the below command instead and try

del /S /Q X:\Path\to\directory\*.*

Wednesday, September 27, 2017 7:00 AM
• Drive mappings are per-user, so if the user running the scheduled task does not have that drive mapping, of course the E: drive will not exist. If that's the case, specify the UNC path to the directory rather than a drive letter.

If E: is a local drive, then my only guess is that the user running the scheduled task does not have permission to remove files from those directories. (This could also be the case if you use a UNC path.)

-- Bill Stewart [Bill_Stewart]

Wednesday, September 27, 2017 2:01 PM
• It does make some space into drive when I run the schedule task manually and complete with no issue. When I look into the folders the subfolder and files still exist. How could I generate log file to see why it is not deleting the rest.

batch file after update-

@echo off
del /S /Q E:\Apple\*.*
del /S /Q E:\Pet\*.*
del /S /Q E:\Animal\*.*
del /S /Q E:\IT\*.*
del /S /Q E:\device\*.*
del /S /Q E:\equipment\*.*
exit