using System.IO;
namespace Semmle.Util
{
public static class FileUtils
{
public static string ConvertToWindows(string path)
{
return path.Replace('/', '\\');
}
public static string ConvertToUnix(string path)
{
return path.Replace('\\', '/');
}
public static string ConvertToNative(string path)
{
return Path.DirectorySeparatorChar == '/' ?
path.Replace('\\', '/') :
path.Replace('/', '\\');
}
///
/// Moves the source file to the destination, overwriting the destination file if
/// it exists already.
///
/// Source file.
/// Target file.
public static void MoveOrReplace(string src, string dest)
{
// Potential race condition here.
// .net offers the facility to either move a file, or to replace it.
File.Delete(dest);
File.Move(src, dest);
}
///
/// Attempt to delete the given file (ignoring I/O exceptions).
///
/// The file to delete.
public static void TryDelete(string file)
{
try
{
File.Delete(file);
}
catch (IOException)
{
// Ignore
}
}
}
}