Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

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

powershell

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

Your Answer

 
discard

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.