SIL.FieldWorks.Common.RootSites.CollectorEnv.RenameOutputToPassN C# (CSharp) Method

RenameOutputToPassN() public static method

Renames the output to pass N.
public static RenameOutputToPassN ( string sOutputFile, int iPass ) : string
sOutputFile string The s output file.
iPass int The i pass.
return string
		public static string RenameOutputToPassN(string sOutputFile, int iPass)
		{
			int idx = sOutputFile.LastIndexOfAny(new char[] { '/', '\\' });
			if (idx < 0)
				idx = 0;
			else
				++idx;
			string sIntermediateFile = sOutputFile.Substring(0, idx) + "Phase" +
				iPass.ToString() +
				"-" + sOutputFile.Substring(idx);
			try
			{
				System.IO.File.Delete(sIntermediateFile);
			}
			catch (Exception e)
			{
				System.Diagnostics.Debug.WriteLine(e.Message);
			}
			for (int tries = 0; tries < 5; tries++)
			{
				try
				{
					File.Move(sOutputFile, sIntermediateFile);
					return sIntermediateFile;
				}
				catch (IOException)
				{
					// Sometimes the system seems to think the file we just wrote is still locked.
					// A short pause may save the day.
					Thread.Sleep(200);
				}
			}
			// If five tries didn't do it, try one more time and let it die if we still can't.
			File.Move(sOutputFile, sIntermediateFile);
			return sIntermediateFile;
		}