Need to clear the contents of a log file(s) which is(are) locked by a process already from command prompt. When I tried doing

echo "" > filename

I get a error saying, the file is locked by a process.

I couldn't even open the file in notepad, clear contents and save.

Currently I'm opening the file in notepad++ and quickly pressing CTRL + a,CTRL+x,CTRL+s :)

Is there a way to get this done from cmd? How is notepad++ able to handle edit and save while notepad is not able to?

link|improve this question
feedback

2 Answers

You could use a program like Unlocker to release the lock: http://www.emptyloop.com/unlocker/

link|improve this answer
feedback

Locked files cannot be deleted, but they can be renamed. It could be that Notepad++ is using "safe saves" – creating a temporary file with the new contents, then quickly deleting the original (this step probably fails) and renaming temporary file to the original name.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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