Kaseya Community

script to delete old log files

  • I found this command line option that should work to delete old files but not working.

    forfiles /p "c:\path\to\logfile\directory" /s /m *.* /d -7 "cmd /c del @path"

    Every time i run it, it tells me "Invalid argument/option - 'cmd /c del @path'.


    Anyone know why?

  • i usually use this application deldate from www.petri.co.il/deldate.htm to delete files based on a certain date. Works well  so far.

  • Forfiles is pretty sensitive depending on the version you're dealing with. For example, some versions only take hyphens and not slashes on the switches. Some are case-sensitive. You have to play with it, unfortunately.

    In this case, I think you need a /c before your "cmd" part.

    [edited by: SMason at 6:24 PM (GMT -7) on 6-22-2012] Typo
  • ...or just use deldate. I have not used it, but it looks cool and Petri is a very credible source.

  • I have a vbs script that I use quite succcessfully on client servers to clean up old files/folders based on a specific age...I can get a copy and attach t if you'd like.

  • Thanks guys. I'll try out those things from petri.

    Mark, if i cant get those to work ill try your vbs. Thanks

  • rattrap,

    In the requirements for deldate it says Windows NT4/2000/XP/2003. Ever try it on windows 7 or server 2008?

  • Tested on windows 7 and seems to work.

    Do you know if there are any other command line option? Like one to also search sub-folders.

  • Tested on 2008 to remove 60 days old reports :

    forfiles /P "e:\kaseya\webpages\datareports\1" /S /M "_iVITa dagelijks overzicht.html" /D -60 /C "cmd /c del @PATH"

  • info about forfiles on the internet :


  • forfiles /P "e:\kaseya\webpages\datareports\1" /S /M "_iVITa dagelijks overzicht.html" /D -60 /C "cmd /c del @PATH"


    Why do you have this (bold part) in the command line? what does that do?

  • Never mind.