public static string MoveToSaveFolder(string formatString, Programme progInfo, Episode epInfo, string baseSavePath, string extension, string sourceFile) { string rootName = Path.Combine(baseSavePath, CreateSaveFileName(formatString, progInfo, epInfo)); // Make sure the save folder exists (to support subfolders in the save file name template) Directory.CreateDirectory(OsUtils.GetDirectoryName(rootName)); for (int diffNum = 0; ; diffNum++) { string savePath = rootName + (diffNum > 0 ? diffNum.ToString(CultureInfo.CurrentCulture) : string.Empty) + "." + extension; if (savePath == sourceFile) { // File is already named correctly, nothing to do return(savePath); } if (!File.Exists(savePath)) { try { OsUtils.MoveFile(sourceFile, savePath); } catch (IOException e) { // We only want to handle IOException itself as a // number of IOException subclasses are thrown for // other cases we don't want to handle if (e.GetType() == typeof(IOException)) { // Destination file created since File.Exists check continue; } throw; } return(savePath); } } }