I am trying to convert BMP files to a folder in jpg and then delete old files. The code works fine, except that it cannot remove BMP.
DirectoryInfo di = new DirectoryInfo(args[0]); FileInfo[] files = di.GetFiles("*.bmp"); foreach (FileInfo file in files) { string newFile = file.FullName.Replace("bmp", "jpg"); Bitmap bm = (Bitmap)Image.FromFile(file.FullName); bm.Save(newFile, ImageFormat.Jpeg); } for (int i = 0; i < files.Length; i++) files[i].Delete();
These files are not used by another program / process, as the error indicates, so I assume the problem is here. But for me, the code seems beautiful, as I do everything sequentially. This is all there is in the program, so the error cannot be caused by code elsewhere.
source share