本文整理汇总了C#中Pri.LongPath.FileInfo类的典型用法代码示例。如果您正苦于以下问题:C# Pri.LongPath.FileInfo类的具体用法?C# Pri.LongPath.FileInfo怎么用?C# Pri.LongPath.FileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pri.LongPath.FileInfo类属于命名空间,在下文中一共展示了Pri.LongPath.FileInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanCreateFileInfoWithLongPathFile
public void CanCreateFileInfoWithLongPathFile()
{
string tempLongPathFilename;
do
{
tempLongPathFilename = Path.Combine(longPathDirectory, Path.GetRandomFileName());
} while (File.Exists(tempLongPathFilename));
Assert.IsFalse(File.Exists(tempLongPathFilename));
using (var writer = File.CreateText(tempLongPathFilename))
{
writer.WriteLine("test");
}
try
{
Assert.IsTrue(File.Exists(tempLongPathFilename));
var fileInfo = new FileInfo(tempLongPathFilename);
Assert.IsNotNull(fileInfo); // just to use fileInfo variable
}
finally
{
File.Delete(tempLongPathFilename);
}
}
示例2: TestCreateText
public void TestCreateText()
{
var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file20.ext").ToString();
var fi = new FileInfo(tempLongPathFilename);
Assert.IsFalse(fi.Exists);
using (fi.CreateText())
{
}
try
{
Assert.IsTrue(File.Exists(fi.FullName)); // don't use FileInfo.Exists, it caches existance
}
finally
{
fi.Delete();
}
}
示例3: TestOpenAppend
public void TestOpenAppend()
{
var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file26.ext").ToString();
var fi = new FileInfo(tempLongPathFilename);
using (var streamWriter = fi.CreateText())
{
streamWriter.WriteLine("file26");
}
try
{
using (var fileStream = fi.Open(System.IO.FileMode.Append))
{
Assert.IsNotNull(fileStream);
using (var streamWriter = new System.IO.StreamWriter(fileStream))
{
streamWriter.WriteLine("eof");
}
}
Assert.AreEqual("file26" + Environment.NewLine + "eof" + Environment.NewLine, File.ReadAllText(fi.FullName));
}
finally
{
File.Delete(tempLongPathFilename);
}
}
示例4: TestDirectoryWithRoot
public void TestDirectoryWithRoot()
{
var fi = new FileInfo(@"C:\");
Assert.IsNull(fi.Directory);
}
示例5: FileInfoReturnsCorrectDirectoryForLongPathFile
public void FileInfoReturnsCorrectDirectoryForLongPathFile()
{
Assert.IsTrue(Directory.Exists(longPathDirectory));
string tempLongPathFilename;
do
{
tempLongPathFilename = Path.Combine(longPathDirectory, Path.GetRandomFileName());
} while (File.Exists(tempLongPathFilename));
Assert.IsFalse(File.Exists(tempLongPathFilename));
using (var writer = File.CreateText(tempLongPathFilename))
{
writer.WriteLine("test");
}
try
{
Assert.IsTrue(File.Exists(tempLongPathFilename));
var fileInfo = new FileInfo(tempLongPathFilename);
Assert.AreEqual(longPathDirectory, fileInfo.Directory.FullName);
Assert.AreEqual(Path.GetFileName(longPathDirectory), fileInfo.Directory.Name);
}
finally
{
File.Delete(tempLongPathFilename);
}
}
示例6: TestSetLastWriteTimeUtcMissingFile
public void TestSetLastWriteTimeUtcMissingFile()
{
var filename = Path.Combine(longPathDirectory, "gibberish.ext");
DateTime dateTime = DateTime.UtcNow.AddDays(1);
var fi = new FileInfo(filename);
fi.LastWriteTimeUtc = dateTime;
}
示例7: TestSetIsReadOnly
public void TestSetIsReadOnly()
{
var filename = Util.CreateNewFile(longPathDirectory);
var fi = new FileInfo(filename);
try
{
fi.IsReadOnly = true;
Assert.IsTrue(fi.IsReadOnly);
}
finally
{
fi.IsReadOnly = false;
fi.Delete();
}
}
示例8: TestSetAccessControl
public void TestSetAccessControl()
{
var filename = Util.CreateNewFile(longPathDirectory);
try
{
var fi = new FileInfo(filename);
var security = new FileSecurity();
fi.SetAccessControl(security);
}
finally
{
File.Delete(filename);
}
}
示例9: TestLengthWithBadPath
public void TestLengthWithBadPath()
{
var filename = Util.CreateNewFile(longPathDirectory);
Pri.LongPath.FileInfo fi;
try
{
fi = new FileInfo(filename);
}
catch
{
File.Delete(filename);
throw;
}
fi.Delete();
fi.Refresh();
var l = fi.Length;
}
示例10: TestLastWriteTime
public void TestLastWriteTime()
{
var filename = Util.CreateNewFile(longPathDirectory);
try
{
var dateTime = DateTime.Now.AddDays(1);
{
var fiTemp = new FileInfo(filename) { LastWriteTime = dateTime };
}
var fi = new FileInfo(filename);
Assert.AreEqual(dateTime, fi.LastWriteTime);
}
finally
{
File.Delete(filename);
}
}
示例11: TestGetIsReadOnly
public void TestGetIsReadOnly()
{
var filename = Util.CreateNewFile(longPathDirectory);
try
{
var fi = new FileInfo(filename);
Assert.IsTrue(fi.Exists);
Assert.IsFalse(fi.IsReadOnly);
}
finally
{
File.Delete(filename);
}
}
示例12: TestGetAccessControlSections
public void TestGetAccessControlSections()
{
var filename = Util.CreateNewFile(longPathDirectory);
try
{
var fi = new FileInfo(filename);
FileSecurity security = fi.GetAccessControl(AccessControlSections.Access);
Assert.IsNotNull(security);
Assert.AreEqual(typeof(FileSystemRights), security.AccessRightType);
Assert.AreEqual(typeof(FileSystemAccessRule), security.AccessRuleType);
Assert.AreEqual(typeof(FileSystemAuditRule), security.AuditRuleType);
Assert.IsTrue(security.AreAccessRulesCanonical);
Assert.IsTrue(security.AreAuditRulesCanonical);
Assert.IsFalse(security.AreAccessRulesProtected);
Assert.IsFalse(security.AreAuditRulesProtected);
var securityGetAccessRules = security.GetAuditRules(true, true, typeof(System.Security.Principal.NTAccount)).Cast<FileSystemAccessRule>();
Assert.AreEqual(0, securityGetAccessRules.Count());
AuthorizationRuleCollection perm = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
var ntAccount = new System.Security.Principal.NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
FileSystemAccessRule rule = perm.Cast<FileSystemAccessRule>().SingleOrDefault(e => ntAccount == e.IdentityReference);
Assert.IsNotNull(rule);
Assert.IsTrue((rule.FileSystemRights & FileSystemRights.FullControl) != 0);
}
finally
{
File.Delete(filename);
}
}
示例13: TestDisplayPath
public void TestDisplayPath()
{
var sfi = new System.IO.FileInfo(@"c:\Windows\notepad.exe");
var fi = new FileInfo(@"c:\Windows\notepad.exe");
Assert.AreEqual(sfi.ToString(), fi.DisplayPath);
}
示例14: TestDecrypt
public void TestDecrypt()
{
var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString();
try
{
using (var s = File.Create(tempLongPathFilename, 200))
{
}
var preAttrib = File.GetAttributes(tempLongPathFilename);
Assert.AreEqual((FileAttributes)0, (preAttrib & FileAttributes.Encrypted));
var fi = new FileInfo(tempLongPathFilename);
fi.Encrypt();
var postAttrib = File.GetAttributes(tempLongPathFilename);
Assert.AreEqual(FileAttributes.Encrypted, (postAttrib & FileAttributes.Encrypted));
fi.Decrypt();
postAttrib = File.GetAttributes(tempLongPathFilename);
Assert.AreEqual((FileAttributes)0, (postAttrib & FileAttributes.Encrypted));
}
finally
{
File.Delete(tempLongPathFilename);
}
}
示例15: TestCreateTextAndWrite
public void TestCreateTextAndWrite()
{
Assert.IsTrue(Directory.Exists(longPathDirectory));
string tempLongPathFilename;
do
{
tempLongPathFilename = Path.Combine(longPathDirectory, Path.GetRandomFileName());
} while (File.Exists(tempLongPathFilename));
Assert.IsFalse(File.Exists(tempLongPathFilename));
const string fileText = "test";
using (var writer = File.CreateText(tempLongPathFilename))
{
writer.WriteLine(fileText);
}
try
{
Assert.IsTrue(File.Exists(tempLongPathFilename));
var fileInfo = new FileInfo(tempLongPathFilename);
Assert.AreEqual(fileText.Length + Environment.NewLine.Length, fileInfo.Length);
}
finally
{
File.Delete(tempLongPathFilename);
}
}