jellyfin-server/MediaBrowser.Controller/IO/FileSystem.cs

93 lines
3.0 KiB
C#
Raw Normal View History

using MediaBrowser.Model.Logging;
using System;
2013-02-21 01:33:05 +00:00
using System.IO;
2013-02-23 07:57:11 +00:00
namespace MediaBrowser.Controller.IO
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Class FileSystem
/// </summary>
public static class FileSystem
{
/// <summary>
/// Gets the creation time UTC.
2013-02-21 01:33:05 +00:00
/// </summary>
/// <param name="info">The info.</param>
/// <param name="logger">The logger.</param>
/// <returns>DateTime.</returns>
public static DateTime GetLastWriteTimeUtc(FileSystemInfo info, ILogger logger)
2013-02-21 01:33:05 +00:00
{
// This could throw an error on some file systems that have dates out of range
2013-02-21 01:33:05 +00:00
try
2013-02-21 01:33:05 +00:00
{
2013-05-05 04:49:49 +00:00
return info.LastWriteTimeUtc;
2013-02-21 01:33:05 +00:00
}
catch (Exception ex)
2013-02-21 01:33:05 +00:00
{
logger.ErrorException("Error determining LastAccessTimeUtc for {0}", ex, info.FullName);
return DateTime.MinValue;
2013-02-21 01:33:05 +00:00
}
}
/// <summary>
/// Gets the creation time UTC.
2013-02-21 01:33:05 +00:00
/// </summary>
/// <param name="info">The info.</param>
/// <param name="logger">The logger.</param>
/// <returns>DateTime.</returns>
public static DateTime GetCreationTimeUtc(FileSystemInfo info, ILogger logger)
2013-02-21 01:33:05 +00:00
{
// This could throw an error on some file systems that have dates out of range
2013-02-21 01:33:05 +00:00
try
2013-02-21 01:33:05 +00:00
{
return info.CreationTimeUtc;
2013-02-21 01:33:05 +00:00
}
catch (Exception ex)
2013-02-21 01:33:05 +00:00
{
logger.ErrorException("Error determining CreationTimeUtc for {0}", ex, info.FullName);
return DateTime.MinValue;
2013-02-21 01:33:05 +00:00
}
}
/// <summary>
/// Copies all.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <exception cref="System.ArgumentNullException">source</exception>
/// <exception cref="System.ArgumentException">The source and target directories are the same</exception>
public static void CopyAll(string source, string target)
{
if (string.IsNullOrEmpty(source))
{
throw new ArgumentNullException("source");
}
if (string.IsNullOrEmpty(target))
{
throw new ArgumentNullException("target");
}
if (source.Equals(target, StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("The source and target directories are the same");
}
// Check if the target directory exists, if not, create it.
Directory.CreateDirectory(target);
2013-02-21 01:33:05 +00:00
foreach (var file in Directory.EnumerateFiles(source))
{
File.Copy(file, Path.Combine(target, Path.GetFileName(file)), true);
}
// Copy each subdirectory using recursion.
foreach (var dir in Directory.EnumerateDirectories(source))
{
CopyAll(dir, Path.Combine(target, Path.GetFileName(dir)));
}
}
2013-10-01 19:18:52 +00:00
}
2013-02-21 01:33:05 +00:00
}