Batch file to delete files older than N days

前端 未结 24 2501
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 11:11

I am looking for a way to delete all files older than 7 days in a batch file. I\'ve searched around the web, and found some examples with hundreds of lines of code, and oth

24条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 11:58

    My command is

    forfiles -p "d:\logs" -s -m*.log -d-15 -c"cmd /c del @PATH\@FILE" 
    

    @PATH - is just path in my case, so I had to use @PATH\@FILE

    also forfiles /? not working for me too, but forfiles (without "?") worked fine.

    And the only question I have: how to add multiple mask (for example ".log|.bak")?

    All this regarding forfiles.exe that I downloaded here (on win XP)

    But if you are using Windows server forfiles.exe should be already there and it is differs from ftp version. That is why I should modify command.

    For Windows Server 2003 I'm using this command:

    forfiles -p "d:\Backup" -s -m *.log -d -15 -c "cmd /c del @PATH"
    

提交回复
热议问题