none
Delete files and folder using bat file via schedule task RRS feed

  • 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


    Muhammad Mehdi

    • Changed type Bill_Stewart Tuesday, November 7, 2017 10:20 PM
    • Moved by Bill_Stewart 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


    Muhammad Mehdi

    Wednesday, September 27, 2017 11:35 PM
  • Your script does not log any information or errors. You could do this by redirecting the output of each del command to a file. Search for cmd redirection operators for examples of how to redirect standard output and standard error to a log file.


    -- Bill Stewart [Bill_Stewart]

    Thursday, September 28, 2017 1:56 PM