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

Christmas Greetings from “The Bishops”

Dear everyone,

It’s that time of year again and despite appearances, we haven’t “forgotten” to write cards, we’ve decided to donate our card/postal money to charity again. This year my Mum had a stroke during the summer so we’ve decided to donate our money to the Stroke Association, which is dedicated to improving the lives of people who have been affected by a stroke.

Apart from Mum’s bad news, Dad has also been in and out of hospital having lower back surgery for arthrosclerosis. Thankfully he’s recovering well. I’ve been in hospital too, for a second ankle fusion operation. I’m very hopeful that this second fusion will mean an end to ankle pain and a return to better mobility in 2016. Sarah’s Dad’s been in hospital too and thankfully he’s improving. All we can say is “thank goodness for the NHS” 🙂

Now for the better news…. James and Katie are both doing well at school. James is now in 2nd year seniors and Katie takes her 11+ in January. They both seem to be enjoying school as well as Scouting, swimming and playing in the school band. James has taken up Rugby, so the World Cup was a good way to kindle his enthusiasm (until England crashed out that is). Both James and Katie took up sailing when we had a week away in Scotland and they’re hoping to carry on with that next year.

Here are a few pictures of the year:

20150715_083724 IMG_1806
 20150811_150306  20151016_175749_HDR  2015-09-26 08-34-03 PM
 2015-12-24 18_29_36-Start    2015-12-24 18_15_30-Start

Here is our now (almost) traditional annual “Elf Yourself” video.

Lots of love and Christmas cheer from

sig
Richard, Sarah, James and Katie.