当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.Dispose方法代码示例

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


在下文中一共展示了FileInfo.Dispose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Write

 protected override void Write(string path, string content)
 {
     var writer = new FileInfo(path).AppendText();
     writer.Write(content);
     writer.Dispose();
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:AppendText.cs

示例2: runTest


//.........这里部分代码省略.........
            iCountTestcases++;
            if (fsArr.Length != 2)
            {
                iCountErrors++;
                printerr("Error_948yv! Incorrect number of files==" + fsArr.Length);
            }
            names = new String[fsArr.Length];
            i = 0;
            foreach (FileSystemInfo fs in fsArr)
                names[i++] = fs.Name;
            iCountTestcases++;
            if (Array.IndexOf(names, "Test1Dir2") < 0)
            {
                iCountErrors++;
                printerr("Error_247yg! Incorrect name==" + fsArr[0].Name);
            }
            iCountTestcases++;
            if (Array.IndexOf(names, "TestDir2") < 0)
            {
                iCountErrors++;
                printerr("Error_24gy7! Incorrect name==" + fsArr[1].Name);
            }

            // [] Search criteria Beginning and ending with '*'

            using (new FileInfo(Path.Combine(dir2.FullName, "AAABB")).Create())
            {
                Directory.CreateDirectory(Path.Combine(dir2.FullName, "aaabbcc"));

                fsArr = dir2.GetFileSystemInfos("*BB*");
                iCountTestcases++;
                if (fsArr.Length != (Interop.IsWindows ? 2 : 1))
                {
                    iCountErrors++;
                    printerr("Error_4y190! Incorrect number of files==" + fsArr.Length);
                }
                names = new String[fsArr.Length];
                i = 0;
                foreach (FileSystemInfo fs in fsArr)
                    names[i++] = fs.Name;

                if (Interop.IsWindows)
                {
                    iCountTestcases++;
                    if (Array.IndexOf(names, "aaabbcc") < 0)
                    {
                        iCountErrors++;
                        printerr("Error_956yb! Incorrect name==" + fsArr[0]);
                        foreach (FileSystemInfo s in fsArr)
                            Console.WriteLine(s.Name);
                    }
                }
                if (Array.IndexOf(names, "AAABB") < 0)
                {
                    iCountErrors++;
                    printerr("Error_48yg7! Incorrect name==" + fsArr[1]);
                    foreach (FileSystemInfo s in fsArr)
                        Console.WriteLine(s.Name);
                }
                strLoc = "Loc_0001";
            }

            // [] Should not search on fullpath
            // [] Search Criteria without match should return empty array

            fsArr = dir2.GetFileSystemInfos("Directory");
            if (fsArr.Length != 0)
            {
                iCountErrors++;
                printerr("Error_209v7! Incorrect number of files==" + fsArr.Length);
            }

            using (new FileInfo(Path.Combine(dir2.FullName, "TestDir1", "Test.tmp")).Create())
            {
                fsArr = dir2.GetFileSystemInfos(Path.Combine("TestDir1", "*"));
                if (fsArr.Length != 1)
                {
                    printerr("Error_28gyb! Incorrect number of files");
                }
            }
            f1.Dispose();
            f2.Dispose();
            f3.Dispose();
            f4.Dispose();
            f5.Dispose();
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine("Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
        }
        ////  Finish Diagnostics
        if (iCountErrors != 0)
        {
            Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString());
        }

        FailSafeDirectoryOperations.DeleteDirectory(dirName, true);
        Assert.Equal(0, iCountErrors);
    }
开发者ID:brianjsykes,项目名称:corefx,代码行数:101,代码来源:GetFileSystemInfos_str.cs

示例3: runTest


//.........这里部分代码省略.........
                printerr("Error_1987y! Incorrect name==" + strArr[1]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir3") < 0)
            {
                iCountErrors++;
                printerr("Error_4yt76! Incorrect name==" + strArr[2]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1File2") < 0)
            {
                iCountErrors++;
                printerr("Error_3y775! Incorrect name==" + strArr[3]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1Dir2") < 0)
            {
                iCountErrors++;
                printerr("Error_90885! Incorrect name==" + strArr[4]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestFile1") < 0)
            {
                iCountErrors++;
                printerr("Error_879by! Incorrect name==" + strArr[5]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestFile2") < 0)
            {
                iCountErrors++;
                printerr("Error_29894! Incorrect name==" + strArr[6]);
            }

            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();
            fs4.Dispose();

            // [] Search criteria beginning with '*'

            strArr = Directory.GetFileSystemEntries(dir2.Name, "*2");
            iCountTestcases++;
            if (strArr.Length != 4)
            {
                iCountErrors++;
                printerr("Error_8019x! Incorrect number of files==" + strArr.Length);
            }

            for (int iLoop = 0; iLoop < strArr.Length; iLoop++)
                strArr[iLoop] = Path.GetFileName(strArr[iLoop]);

            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1Dir2") < 0)
            {
                iCountErrors++;
                printerr("Error_247yg! Incorrect name==" + strArr[0]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir2") < 0)
            {
                iCountErrors++;
                printerr("Error_24gy7! Incorrect name==" + strArr[1]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1File2") < 0)
            {
开发者ID:johnhhm,项目名称:corefx,代码行数:67,代码来源:GetFileSystemEntries_str_str.cs

示例4: runTest

    public static void runTest()
    {
        int iCountErrors = 0;
        int iCountTestcases = 0;
        String strLoc = "Loc_000oo";
        String strValue = String.Empty;


        try
        {
            /////////////////////////  START TESTS ////////////////////////////
            ///////////////////////////////////////////////////////////////////

            DirectoryInfo dir2;
            String dirName = Path.GetRandomFileName();
            FileInfo[] filArr;

            if (Directory.Exists(dirName))
                Directory.Delete(dirName, true);

            // [] Should return zero length array for an empty directory
            //-----------------------------------------------------------------
            strLoc = "Loc_4y982";

            dir2 = Directory.CreateDirectory(dirName);
            filArr = dir2.GetFiles();
            iCountTestcases++;
            if (filArr.Length != 0)
            {
                iCountErrors++;
                printerr("Error_207v7! Incorrect number of directories returned");
            }
            //-----------------------------------------------------------------


            // [] Create a directorystructure and get all the files
            //-----------------------------------------------------------------
            strLoc = "Loc_2398c";

            dir2.CreateSubdirectory("TestDir1");
            dir2.CreateSubdirectory("TestDir2");
            dir2.CreateSubdirectory("TestDir3");
            FileStream fs1 = new FileInfo(Path.Combine(dir2.FullName, "TestFile1")).Create();
            FileStream fs2 = new FileInfo(Path.Combine(dir2.FullName, "TestFile2")).Create();
            FileStream fs3 = new FileInfo(Path.Combine(dir2.FullName, "Test.bat")).Create();
            FileStream fs4 = new FileInfo(Path.Combine(dir2.FullName, "Test.exe")).Create();
            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();
            fs4.Dispose();

            iCountTestcases++;
            filArr = dir2.GetFiles();
            iCountTestcases++;
            if (filArr.Length != 4)
            {
                iCountErrors++;
                printerr("Error_1yt75! Incorrect number of directories returned" + filArr.Length);
            }

            String[] names = new String[4];
            int i = 0;
            foreach (FileInfo f in filArr)
                names[i++] = f.Name;
            
            if (!Interop.IsWindows) // test is expecting sorted order as provided by Windows
            {
                Array.Sort(names);
            }

            iCountTestcases++;
            if (Array.IndexOf(names, "Test.bat") < 0)
            {
                iCountErrors++;
                printerr("Error_3y775! Incorrect name==" + filArr[0].Name);
            }
            iCountTestcases++;
            if (Array.IndexOf(names, "Test.exe") < 0)
            {
                iCountErrors++;
                printerr("Error_90885! Incorrect name==" + filArr[1].Name);
            }
            iCountTestcases++;
            if (Array.IndexOf(names, "TestFile1") < 0)
            {
                iCountErrors++;
                printerr("Error_879by! Incorrect name==" + filArr[2].Name);
            }
            iCountTestcases++;
            if (Array.IndexOf(names, "TestFile2") < 0)
            {
                iCountErrors++;
                printerr("Error_29894! Incorrect name==" + filArr[3].Name);
            }

            File.Delete(Path.Combine(dirName, "TestFile1"));
            File.Delete(Path.Combine(dirName, "TestFile2"));

            filArr = dir2.GetFiles();
            iCountTestcases++;
//.........这里部分代码省略.........
开发者ID:johnhhm,项目名称:corefx,代码行数:101,代码来源:GetFiles.cs

示例5: runTest


//.........这里部分代码省略.........
            if (Array.IndexOf(names, "Test1File2") < 0)
            {
                iCountErrors++;
                printerr("Error_167yb! Incorrect name==" + filArr[0].Name);
            }
            iCountTestcases++;
            if (Array.IndexOf(names, "TestFile2") < 0)
            {
                iCountErrors++;
                printerr("Error_49yb7! Incorrect name==" + filArr[1].Name);
            }

            // [] Multiple wildcards in searchstring

            strLoc = "Loc_9438y";
            filArr = dir2.GetFiles("*es*F*l*");
            iCountTestcases++;
            if (filArr.Length != 5)
            {
                iCountErrors++;
                printerr("Error_38fy3! Incorrect number of files returned, expected==5, got==" + filArr.Length);
            }


            // [] Searchstring beginning and ending with '*'
            // [] Search should be case insensitive
            dirName = Path.GetRandomFileName();
            Directory.CreateDirectory(dirName);
            dir2 = new DirectoryInfo(dirName);
            FileInfo fi1 = new FileInfo(Path.Combine(dirName, "AAABB"));
            FileInfo fi2 = new FileInfo(Path.Combine(dirName, "aaabbcc"));
            FileStream fs1 = fi1.Create();
            FileStream fs2 = fi2.Create();
            fs1.Dispose();
            fs2.Dispose();

            filArr = dir2.GetFiles("*BB*");
            iCountTestcases++;
            if (filArr.Length != (Interop.IsWindows ? 2 : 1))
            {
                iCountErrors++;
                printerr("Error_4y190! Incorrect number of files==" + filArr.Length);
            }
            names = new String[filArr.Length];
            i = 0;
            foreach (FileInfo f in filArr)
            {
                names[i++] = f.Name;
            }

            iCountTestcases++;
            if (Array.IndexOf(names, "AAABB") < 0)
            {
                iCountErrors++;
                printerr("Error_956yb! Incorrect name==" + filArr[0].Name);
            }
            if (Interop.IsWindows)
            {
                iCountTestcases++;
                if (Array.IndexOf(names, "aaabbcc") < 0)
                {
                    iCountErrors++;
                    printerr("Error_48yg7! Incorrect name==" + filArr[1].Name);
                }
            }
开发者ID:johnhhm,项目名称:corefx,代码行数:66,代码来源:GetFiles_str.cs

示例6: runTest


//.........这里部分代码省略.........
            //With valid directory
            dir2 = new DirectoryInfo(dirName);
            dir2.Create();

            strArr = Directory.GetFileSystemEntries(dirName);
            iCountTestcases++;
            if (strArr.Length != 0)
            {
                iCountErrors++;
                printerr("Error_207v7! Incorrect number of directories returned");
            }

            // [] Create a directorystructure get all the filesystementries
            //-----------------------------------------------------------------
            strLoc = "Loc_2398c";

            dir2.CreateSubdirectory("TestDir1");
            dir2.CreateSubdirectory("TestDir2");
            dir2.CreateSubdirectory("TestDir3");
            FileStream fs1 = new FileInfo(Path.Combine(dir2.ToString(), "TestFile1")).Create();
            FileStream fs2 = new FileInfo(Path.Combine(dir2.ToString(), "TestFile2")).Create();
            FileStream fs3 = new FileInfo(Path.Combine(dir2.ToString(), "Test.bat")).Create();
            FileStream fs4 = new FileInfo(Path.Combine(dir2.ToString(), "Test.exe")).Create();

            iCountTestcases++;
            strArr = Directory.GetFileSystemEntries(dir2.Name);
            iCountTestcases++;
            if (strArr.Length != 7)
            {
                iCountErrors++;
                printerr("Error_1yt75! Incorrect number of directories returned" + strArr.Length);
            }

            for (int iLoop = 0; iLoop < strArr.Length; iLoop++)
                strArr[iLoop] = Path.GetFileName(strArr[iLoop]);

            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir1") < 0)
            {
                iCountErrors++;
                printerr("Error_4yg76! Incorrect name==" + strArr[0]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir2") < 0)
            {
                iCountErrors++;
                printerr("Error_1987y! Incorrect name==" + strArr[1]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir3") < 0)
            {
                iCountErrors++;
                printerr("Error_4yt76! Incorrect name==" + strArr[2]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test.bat") < 0)
            {
                iCountErrors++;
                printerr("Error_3y775! Incorrect name==" + strArr[3]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test.exe") < 0)
            {
                iCountErrors++;
                printerr("Error_90885! Incorrect name==" + strArr[4]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestFile1") < 0)
            {
                iCountErrors++;
                printerr("Error_879by! Incorrect name==" + strArr[5]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestFile2") < 0)
            {
                iCountErrors++;
                printerr("Error_29894! Incorrect name==" + strArr[6]);
            }

            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();
            fs4.Dispose();
            if (Directory.Exists(dirName))
                Directory.Delete(dirName, true);
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            printerr("Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
        }
        ////  Finish Diagnostics

        if (iCountErrors != 0)
        {
            Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString());
        }

        Assert.Equal(0, iCountErrors);
    }
开发者ID:johnhhm,项目名称:corefx,代码行数:101,代码来源:GetFileSystemEntries_str.cs


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