Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script the generates a log file and appends to it every run. It also gets emailed to me every week. However with it running daily, it can get quite large. Is there a way to delete it at the start of the script on windows 7 if it's bigger than say, 1MB?

share|improve this question
up vote 1 down vote accepted

Presuming your script is not in powershell. Make sure your system is setup to allow powershell scripts. Do some test runs first, but you can write something similar to this in a file ending with the .ps1 extention and call it from your script as


$FILEINF=get-item .\<YOURFILE>
if( ($FILEINF.length/1MB) -gt 1){
   remove-item $FILEINF.fullname
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.