Batch file to delete files older than x days from folders in Windows

I’ve been working for a client over recent months and part of my resposibility has been to look after a number of servers used for performance testing. Occasionally drives fill up on the server farm causing outages and obvious interruptions to testing.

It would be a near full-time job to manage all these servers, so to reduce the chance of temporary files from filling up drives and causing problems, I looked into creating a scheduled task to delete old temporary files. Since my server estate is varied, I didnt want to use PowerShell so I opted for an old “DOS” command, FORFILES.

This seems to have done the trick for me:
forfiles /s /m *.* /d -7 /c "cmd /c del @path"

(This command deletes all files that are more than 7 days old from the folder in which it runs.)

Update – To remove folders as well:
forfiles /S /D -7 /C "cmd /c IF @isdir == TRUE RMDIR @path /S /Q"

(This command deletes all folders that are more than 7 days old from the folder in which it runs. – Run it after deleting the files with the command above.)

 

What can a long-dead Prussian teach us about IT?

I originally wrote this for the Trust IV blog, but I thought it deserved a “republish” here…

As a performance tester, along with many people in the IT-world, I’m often asked to plan for different eventualities. I have to write test plans, software deployment plans or help to provide estimates for how long a piece of work will take.  For predictable, simple work, this is fairly easy and is the sort of thing that people learn in school maths lessons. e.g. “If it takes one man one hour to dig a hole, how long will it take two men to dig a similar hole?”

In the IT world it often isn’t as simple as that. To (mis)quote Donald Rumsfeld, things that catch us out are the “unknown unknowns, those things that we don’t know that we don’t know.” How can we be sure that the configuration of a particular server is the same as the last one where we performed a particular task?
How do we know that the test data that we’ve been given is a true representation of live data?
How can we be sure that the business requirements we’ve been given are correct?

With a whole host of unknowns we need to be prepared to change our plans at a moment’s notice.
This is where the “dead Prussian” comes in…..

This cHelmuth_von_Moltke_(1800-1891)hap is Helmut von Moltke the Elder; a Prussian army officer who died in Berlin in 1891. He was the chief of staff of the Prussian army and an excellent strategist. Rather than directing his armies with explicit commands, which ran the risk of becoming irrelevant quickly, he recognised that it made more sense to describe an overall strategic plan to his officers and rely on them to help him to achieve his objectives.

 

He recognised that military strategy was best described as a system of “options” since only the beginning of a military operation was plannable. He tasked his officers with calculating numerous possible outcomes and “what if?” scenarios. Only by preparing for multiple possibilities, could he be ensured of success.

His ethos is best described with the quote which is most commonly attributed to him:
“No plan of operations extends with certainty beyond the first encounter with the enemy’s main strength.”

Often abbreviated to:
“No plan survives contact with the enemy.”
I think that “Moltke” would have been at home in the IT world. He rejected a single detailed plan in favour of multiple “what if” plans and empowered his subordinates, trusting them to make the right decisions, despite the fact that he couldn’t always be in contact with them. Although the “military subject matter” of his famous quotes isn’t pertinent in IT, the theme remains relevant.

As I tester, I believe that these quotes are spot on:

  • No test plan survives first contact with application code.
  • No project plan extends with certainty beyond the first milestone.
  • There is no such thing as the “perfect test”, prepare for the unexpected.
  • If something can go wrong, it probably will….. be prepared for it.

Can you think of any other “Moltke-themed” quotations that are relevant to you?

Answers on a postcard….well perhaps in a Tweet to @TrustIV or @RichardBishop