• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# LongPath.FileInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Pri.LongPath.FileInfo的典型用法代码示例。如果您正苦于以下问题:C# Pri.LongPath.FileInfo类的具体用法?C# Pri.LongPath.FileInfo怎么用?C# Pri.LongPath.FileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Pri.LongPath.FileInfo类属于命名空间,在下文中一共展示了Pri.LongPath.FileInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
			}
		}
开发者ID:HMartyrossian,项目名称:LongPath,代码行数:24,代码来源:FileInfoTests.cs


示例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();
            }
        }
开发者ID:KsWare,项目名称:LongPath,代码行数:19,代码来源:FileInfoTests.cs


示例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);
            }
        }
开发者ID:jerriclynsjohn,项目名称:LongPath,代码行数:26,代码来源:FileTests.cs


示例4: TestDirectoryWithRoot

 public void TestDirectoryWithRoot()
 {
     var fi = new FileInfo(@"C:\");
     Assert.IsNull(fi.Directory);
 }
开发者ID:jerriclynsjohn,项目名称:LongPath,代码行数:5,代码来源:FileTests.cs


示例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);
            }
        }
开发者ID:jerriclynsjohn,项目名称:LongPath,代码行数:26,代码来源:FileTests.cs


示例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;
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:7,代码来源:FileInfoTests.cs


示例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();
     }
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:15,代码来源:FileInfoTests.cs


示例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);
     }
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:14,代码来源:FileInfoTests.cs


示例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;
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:17,代码来源:FileInfoTests.cs


示例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);
     }
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:17,代码来源:FileInfoTests.cs


示例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);
     }
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:14,代码来源:FileInfoTests.cs


示例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);
     }
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:28,代码来源:FileInfoTests.cs


示例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);
        }
开发者ID:KsWare,项目名称:LongPath,代码行数:7,代码来源:FileInfoTests.cs


示例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);
            }
        }
开发者ID:KsWare,项目名称:LongPath,代码行数:27,代码来源:FileInfoTests.cs


示例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);
            }
        }
开发者ID:KsWare,项目名称:LongPath,代码行数:26,代码来源:FileInfoTests.cs


示例16: TestOpenWriteWritesCorrectly

 public void TestOpenWriteWritesCorrectly()
 {
     var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file31a.ext").ToString();
     var fi = new FileInfo(tempLongPathFilename);
     try
     {
         using (var fileStream = fi.OpenWrite())
         {
             fileStream.WriteByte(42);
         }
         using (var fileStream = fi.OpenRead())
         {
             Assert.AreEqual(42, fileStream.ReadByte());
         }
     }
     finally
     {
         File.Delete(tempLongPathFilename);
     }
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:20,代码来源:FileInfoTests.cs


示例17: TestReplaceIgnoreMerge

        public void TestReplaceIgnoreMerge()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString();
            using (var fileStream = File.Create(tempLongPathFilename))
            {
                try
                {
                    fileStream.WriteByte(42);
                }
                catch (Exception)
                {
                    File.Delete(tempLongPathFilename);
                    throw;
                }
            }
            var tempLongPathFilename2 = new StringBuilder(longPathDirectory).Append(@"\").Append("filename2.ext").ToString();

            using (var fileStream = File.Create(tempLongPathFilename2))
            {
                try
                {
                    fileStream.WriteByte(52);
                }
                catch (Exception)
                {
                    File.Delete(tempLongPathFilename2);
                    throw;
                }
            }
            var fi = new FileInfo(tempLongPathFilename);
            try
            {
                const bool ignoreMetadataErrors = true;
                var fi2 = fi.Replace(tempLongPathFilename2, null, ignoreMetadataErrors);
                Assert.IsNotNull(fi2);
                Assert.AreEqual(tempLongPathFilename2, fi2.FullName);
                using (var fileStream = File.OpenRead(tempLongPathFilename2))
                {
                    Assert.AreEqual(42, fileStream.ReadByte());
                }
                Assert.IsFalse(File.Exists(tempLongPathFilename));
            }
            finally
            {
                if (File.Exists(tempLongPathFilename))
                    File.Delete(tempLongPathFilename);
                File.Delete(tempLongPathFilename2);
            }
        }
开发者ID:KsWare,项目名称:LongPath,代码行数:49,代码来源:FileInfoTests.cs


示例18: TestMoveTo

        public void TestMoveTo()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file21.ext").ToString();
            var tempDestLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file21-1.ext").ToString();
            Assert.IsFalse(File.Exists(tempLongPathFilename));
            File.Copy(longPathFilename, tempLongPathFilename);
            try
            {
                Assert.IsTrue(File.Exists(tempLongPathFilename));

                var fi = new FileInfo(tempLongPathFilename);
                fi.MoveTo(tempDestLongPathFilename);

                try
                {
                    Assert.IsFalse(File.Exists(tempLongPathFilename));
                    Assert.IsTrue(File.Exists(tempDestLongPathFilename));
                }
                finally
                {
                    File.Delete(tempDestLongPathFilename);
                }
            }
            finally
            {
                if (File.Exists(tempLongPathFilename))
                    File.Delete(tempLongPathFilename);
            }
        }
开发者ID:KsWare,项目名称:LongPath,代码行数:29,代码来源:FileInfoTests.cs


示例19: TestSetCreationTimeMissingFile

 public void TestSetCreationTimeMissingFile()
 {
     var filename = Path.Combine(longPathDirectory, "gibberish.ext");
     DateTime dateTime = DateTime.Now.AddDays(1);
     var fi = new FileInfo(filename);
     fi.CreationTime = dateTime;
 }
开发者ID:KsWare,项目名称:LongPath,代码行数:7,代码来源:FileInfoTests.cs


示例20: TestOpenCreatesEmpty

        public void TestOpenCreatesEmpty()
        {
            var tempLongPathFilename = Path.Combine(longPathDirectory, Path.GetRandomFileName());
            try
            {
                using (var writer = File.CreateText(tempLongPathFilename))
                {
                    writer.WriteLine("test");
                }

                var fi = new FileInfo(tempLongPathFilename);
                using (var fileStream = fi.Open(FileMode.Append, FileAccess.Read, FileShare.Read))
                {
                    Assert.AreEqual(-1, fileStream.ReadByte());
                }

            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
开发者ID:KsWare,项目名称:LongPath,代码行数:22,代码来源:FileInfoTests.cs



注:本文中的Pri.LongPath.FileInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Price类代码示例发布时间:2022-05-24
下一篇:
C# LongPath.DirectoryInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap