CmdExec to delete files not working

  • I'm using Ola Hallengren's maintenance solution with this command to cleanup old output files. However, it is not working. It deletes nothing and returns no error. Any thoughts as to why this isn't working?

    cmd /q /c "For /F "tokens=1 delims=" %v In ('ForFiles /P "\\dba\OutputFiles" /m *_*_*_*.txt /d -30 2^>^&1') do if EXIST "\\dba\OutputFiles"\%v echo del "\\dba\OutputFiles"\%v& del "\\dba\OutputFiles"\%v"

  • Samwell - Friday, July 6, 2018 1:02 PM

    I'm using Ola Hallengren's maintenance solution with this command to cleanup old output files. However, it is not working. It deletes nothing and returns no error. Any thoughts as to why this isn't working?

    cmd /q /c "For /F "tokens=1 delims=" %v In ('ForFiles /P "\\dba\OutputFiles" /m *_*_*_*.txt /d -30 2^>^&1') do if EXIST "\\dba\OutputFiles"\%v echo del "\\dba\OutputFiles"\%v& del "\\dba\OutputFiles"\%v"

    Have you checked the permissions on the \\dba\OutputFiles file share?
    😎
    If the process is running as a local service account, it will not have the necessary permissions.

  • It's running as a SQL Agent job and the service account running SQL Agent has permissions to that folder. It can create the files.

  • Samwell - Monday, July 9, 2018 5:50 AM

    It's running as a SQL Agent job and the service account running SQL Agent has permissions to that folder. It can create the files.

    Could be the fact that there's no space prior to the "&".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply