none
Error Handling in Batch Script RRS feed

  • Question

  • Hi,

    I have a script for deleting files from specific folders - 

    forfiles  /P  X:\<path>  /D -7 /M *.* /S /C "cmd /C del @path /Q"

    forfiles  /P  X:\<path>    /D -7 /M *.* /S /C "cmd /C del @path /Q"

    I need to implement error handling like folder doesn't exist or files not there etc.

    Kindly help me to write the same.

    Thanks,

    Sugata

    Wednesday, February 18, 2015 2:22 PM

Answers

  • Don't worry about trying to write code to catch errors and log information. Just use robocopy.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, February 18, 2015 3:18 PM
    Moderator

All replies

  • there is not much of errorcontrol in batch.

    %ERRORLEVEL% will contain the exit code of the last executed command.  Check this on how to use this


    MCP/MCSA/MCTS/MCITP

    Wednesday, February 18, 2015 2:26 PM
  • Don't worry about trying to write code to catch errors and log information. Just use robocopy.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, February 18, 2015 3:18 PM
    Moderator
  • Hi Bill,

    Thanks for the reply.could you please let me know how it is used? else any good link to follow?

    Regards,

    Sugata

    Wednesday, February 18, 2015 3:55 PM
  • Robocopy is a built-in command.

    There is no need to be helpless. You can find information if you search:

    http://www.bing.com/search?q=robocopy

    Note that this is not a support forum for the robocopy command.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, February 18, 2015 4:04 PM
    Moderator