2013-01-07 23:24:29 +03:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using Umbraco.Core.CodeAnnotations;
|
2012-08-20 10:46:32 -01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.IO
|
2013-08-23 13:41:16 +10:00
|
|
|
|
{
|
2012-11-08 08:27:38 +05:00
|
|
|
|
public static class FileSystemExtensions
|
2012-08-20 10:46:32 -01:00
|
|
|
|
{
|
2013-08-23 13:41:16 +10:00
|
|
|
|
public static long GetSize(this IFileSystem fs, string path)
|
2012-08-20 10:46:32 -01:00
|
|
|
|
{
|
2013-08-23 11:46:55 +10:00
|
|
|
|
using (var s = fs.OpenFile(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
var size = s.Length;
|
|
|
|
|
|
s.Close();
|
2012-08-20 10:46:32 -01:00
|
|
|
|
|
2013-08-23 11:46:55 +10:00
|
|
|
|
return size;
|
|
|
|
|
|
}
|
2012-08-20 10:46:32 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-23 13:41:16 +10:00
|
|
|
|
public static void CopyFile(this IFileSystem fs, string path, string newPath)
|
2012-08-20 10:46:32 -01:00
|
|
|
|
{
|
2012-08-20 11:42:18 -01:00
|
|
|
|
fs.AddFile(newPath, fs.OpenFile(path));
|
2012-08-20 10:46:32 -01:00
|
|
|
|
}
|
2013-01-07 23:24:29 +03:00
|
|
|
|
|
2013-08-23 13:41:16 +10:00
|
|
|
|
public static string GetExtension(this IFileSystem fs, string path)
|
2013-01-07 23:24:29 +03:00
|
|
|
|
{
|
|
|
|
|
|
return Path.GetExtension(fs.GetFullPath(path));
|
|
|
|
|
|
}
|
2013-01-08 00:58:22 +03:00
|
|
|
|
|
2013-08-23 13:41:16 +10:00
|
|
|
|
public static string GetFileName(this IFileSystem fs, string path)
|
2013-01-08 00:58:22 +03:00
|
|
|
|
{
|
|
|
|
|
|
return Path.GetFileName(fs.GetFullPath(path));
|
|
|
|
|
|
}
|
2012-08-20 10:46:32 -01:00
|
|
|
|
}
|
|
|
|
|
|
}
|