2

I want to programmatically rename a file and it could be open. It's a log file. When I was testing my code the rename part didn't work because the log file TestPro.log was open by the TAF (Test Automation Framework).

When TestPro is running and I try to delete the file I get the error "Cannot delete because is being used by another person or program."

Is there any way how to rename a file (programmatically) that is open the way the log file was?

3 Answers 3

1

The solution is to use command line version of Unlocker before moving/removing the file.

2
  • 2
    Yes. that is a way. but, renaming it will render it inaccessible to the program which uses it(TAF in this case). Unlocker is recommended when you don't know which program has locked the file and still want to modify it. May 28, 2012 at 7:43
  • Valid comment! Tested and it looks like TAF doesn't mind :-)
    – Radek
    May 28, 2012 at 23:29
1

The best is MoveFile from Sysinternals.

1
0

I hope you'll find answers here:

There are several reasons why Windows might not allow you to delete a file:

  • The file might be in use in which case you can't delete the file until the program using it gives it up.
  • The file might be marked read-only.
  • The file name might be so long that Windows can't handle it. File names with more than 260 characters in them are often difficult to delete.
  • There are also several reasons why Windows might not allow you to change the name of a file; particularly its extension. All above apply here; as well as...

  • Your system may not be showing file extensions by default.

We'll cover that one first and the others in turn.

[…]

Sometimes you can't seem to delete a file or folder no matter what you do. In this case there are a few programs that might help you.

  • MoveOnBoot
  • Delete FXP Files
  • Delinv
  • Unlocker

If, after all this you still can't rename/delete a file, not certain what else to suggest. Others have this problem often and as different ideas might come up in the FILExt forum I'll change this FAQ to include them. If you find a method that works for you and is not in this FAQ, please drop FILExt a note with details on that method so it can be added to the FAQ.

1
  • 3
    You need to quote everything you didn't write yourself. This is close to plagiarism, so please don't just copy and paste stuff from other websites as answers. Try to describe in your own words if possible.
    – slhck
    May 28, 2012 at 9:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .