0

Unfortunately I don't have direct access to my code at the moment, but the application does the following:

  • Get a string[] files = Directory.GetFiles(dir, "*.mp3", SearchOptions.AllDirectories);
  • Iterate over each file in files and get a generic Tag object (not an IDV3 one specifically, or whatever the format is called)
  • Build a string with a new filename {track no} - {track name} from the Tag object and add it to a list
  • File.Copy(files[i], newFileName, true) to rename the file (copy to the same directory with a new name)

The File.Copy crashes and it tells me another process is using the file. I know for a fact nothing else is using these files, but something somewhere in my code must be locking them and I don't know what, nor how to deduce which bit it is.

I've tried adding myTagObject.Save(); myTagObject.Clear(); myTagObject = null; in case TL# was locking the file but I can't think of anything more I could do there to release it.

sab669
  • 3,984
  • 8
  • 38
  • 75
  • 2
    Probably does. Doubt the Tag object has anything to do with it. Tag doesn't implement IDisposable. But, oh, look, TagLib.File ***does*** implement IDisposable. Probably because it locks the file. Do you dispose the File after you're done using it? –  Aug 10 '15 at 14:49
  • I'm not certain if I create a `TagLib.File` object, I think I just create the `Tag` from the file path in `string[] files` but I'll have to check into that! Thanks. – sab669 Aug 10 '15 at 14:50
  • @Will Alrigth I tried creating the `TagLib.File` object, creating the `Tag` object, getting data from the `Tag`, then I close it and assign null. Dispose & assign null to the `File` as well. Same error-- File in use :( – sab669 Aug 11 '15 at 22:53
  • Can you create a complete, self contained example in a console application that reproduces the issue? Perhaps you're locking the file somewhere else in your codebase? A repro would help. –  Aug 12 '15 at 13:30

0 Answers0