Need help on how to do the coding.


  1. Posts : 369
    Windows 7 Pro 32bit
       #1

    Need help on how to do the coding.


    I have a log file in XML format that i want to delete through task scheduler.
    I want to delete this because the logs accumulate every week and gets as big as 80GB. It affects the performance of the PC.

    The file is located in C:\ProgramData\folder1\folder2\Logs Folder\ErrorLog.xml

    can someone give a code on how to delete this using batch file. I only want to delete the ErrorLog.xml not the folder.

    i already know how to run the batch file on task scheduler. i just don't know how to create the code.

    Thank you
      My Computer


  2. Posts : 10,485
    W7 Pro SP1 64bit
       #2

    Let's save automatic file deletion via scheduled task as the last resort.

    1) Have you tried to figure out why so many errors are being logged?

    2) Have you tried telling that app to log fewer errors? (e.g. change debug/logging level)

    3) Have you tried manually deleting the file, manually recreating the file, then making it read-only. If the app does not complain about not being able to log errors, then this might be a better solution than automated deletion. You can always temporarily remove the read-only attribute if you need to see the errors being logged.
      My Computer


  3. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #3

    Hi ShoTTaS,

    You can schedule for cmd.exe to run the del command on that ErrorLog.xml file of yours.

    E.g., In Task Scheduler you'd input cmd.exe as the Program/script and /c "del "C:\ProgramData\folder1\folder2\Logs Folder\ErrorLog.xml"" in the Add arguments (optional) field.


    ShoTTaS said:
    i already know how to run the batch file on task scheduler. i just don't know how to create the code.
    There's no need for a batch file if you're running just a single command.
    Last edited by Pyprohly; 30 Jun 2015 at 08:15. Reason: Typo
      My Computer


  4. Posts : 369
    Windows 7 Pro 32bit
    Thread Starter
       #4

    hi Pyprohly,

    Hi ShoTTaS,

    You can schedule for cmd.exe to run the del command on that ErrorLog.xml file of yours.

    E.g., In Task Scheduler you'd input cmd.exe as the Program/script and /c "del "C:\ProgramData\folder1\folder2\Logs Folder\ErrorLog.xml"" in the Add arguments (optional) field.
    what does /c stands for? i just want to know.

    i will be using this command that you gave.

    Thank you
      My Computer


  5. Posts : 5,656
    Windows 7 Ultimate x64 SP1
       #5

    See:

    /C Carries out the command specified by the string and then terminates.
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #6

    To further boost the understanding, this is what the full command you're running actually looks like, ShoTTaS --
    Code:
    cmd.exe /c "del "C:\ProgramData\folder1\folder2\Logs Folder\ErrorLog.xml""
    As you see, the /c switch belongs to the Cmd command. We can observe the help information for the Cmd command to figure out what its switches are and do, by running the command cmd /?.
    Code:
    C:\>cmd /?
    Starts a new instance of the Windows command interpreter
    CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
        [[/S] [/C | /K] string]
    /C      Carries out the command specified by string and then terminates
    /K      Carries out the command specified by string but remains
    /S      Modifies the treatment of string after /C or /K (see below)
    /Q      Turns echo off
    /D      Disable execution of AutoRun commands from registry (see below)
    [...]
      My Computer


  7. Posts : 369
    Windows 7 Pro 32bit
    Thread Starter
       #7

    Pyprohly said:
    To further boost the understanding, this is what the full command you're running actually looks like, ShoTTaS --
    Code:
    cmd.exe /c "del "C:\ProgramData\folder1\folder2\Logs Folder\ErrorLog.xml""
    As you see, the /c switch belongs to the Cmd command. We can observe the help information for the Cmd command to figure out what its switches are and do, by running the command cmd /?.
    Code:
    C:\>cmd /?
    Starts a new instance of the Windows command interpreter
    CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
        [[/S] [/C | /K] string]
    /C      Carries out the command specified by string and then terminates
    /K      Carries out the command specified by string but remains
    /S      Modifies the treatment of string after /C or /K (see below)
    /Q      Turns echo off
    /D      Disable execution of AutoRun commands from registry (see below)
    [...]
    Thank you.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:46.
Find Us