Solved Need help on how to do the coding.

ShoTTaS

{ BANANA }
Pro User
VIP
Local time
2:58 AM
Messages
362
Location
Philippines
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP
OS
Windows 7 Pro 32bit
CPU
Dual Core
Antivirus
Trend Micro
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

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
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.


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:

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP
OS
Windows 7 Pro 32bit
CPU
Dual Core
Antivirus
Trend Micro
See:

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

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 SP1
CPU
AMD Phenom 2 1090T
Motherboard
Gigabyte GA-890FXA-UD5
Memory
2x8GB Kingston HyperX Fury Black 1600Mhz Unganged
Graphics Card(s)
MSI GTX 970 Gaming 4G
Sound Card
Realtek On-Board HD 7.1 Audio / Logitech G35
Monitor(s) Displays
3xAcer GD245HQ
Screen Resolution
1920x1080
Hard Drives
Samsung 850 Pro 512GB SSD - OS /
WD Caviar Black SATA 3 - 1 TBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GB - Internal Backup /
Seagate Barracude SATA 3 - 3TB - External Backup/ Sync
PSU
HighPower 1000W
Case
Cooler Master HAF 932
Cooling
Noctua NH-D14
Keyboard
Logitech G19
Mouse
Logitech G500
Internet Speed
100/4 Mbit Cable (100GB quota)
Antivirus
ZoneAlarm Extreme Security / MBAM Pro / MBAE Free / SAS Free
Browser
IE 11 - Firefox - Chrome
Other Info
Logitech F710/ G27/ G940/ Z5500 // TrackIR 5 // Nvidia 3D Surround Vision
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:
[COLOR="silver"]C:\>[/COLOR]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]
[COLOR="Blue"]/C      Carries out the command specified by string and then terminates[/COLOR]
/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)
[COLOR="Silver"][...][/COLOR]
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
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:
[COLOR="silver"]C:\>[/COLOR]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]
[COLOR="Blue"]/C      Carries out the command specified by string and then terminates[/COLOR]
/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)
[COLOR="Silver"][...][/COLOR]

Thank you.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP
OS
Windows 7 Pro 32bit
CPU
Dual Core
Antivirus
Trend Micro
Back
Top