本文整理汇总了C#中FileInfo.Close方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Close方法的具体用法?C# FileInfo.Close怎么用?C# FileInfo.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInfo
的用法示例。
在下文中一共展示了FileInfo.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runTest
//.........这里部分代码省略.........
}
filArr = dir2.GetFiles("*File2");
iCountTestcases++;
if(filArr.Length != 2) {
iCountErrors++;
printerr( "Error_8019x! Incorrect number of files=="+filArr.Length);
}
names = new String[2];
i = 0;
foreach (FileInfo f in filArr)
names[i++] = f.Name;
iCountTestcases++;
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);
}
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);
}
dir2 = new DirectoryInfo(".");
FileInfo fi1 = new FileInfo("AAABB");
FileInfo fi2 = new FileInfo("aaabbcc");
FileStream fs1 = fi1.Create();
FileStream fs2 = fi2.Create();
fs1.Close();
fs2.Close();
filArr = dir2.GetFiles("*BB*");
iCountTestcases++;
#if PLATFORM_UNIX // case-sensitive filesystem
if(filArr.Length != 1) {
#else
if(filArr.Length != 2) {
#endif
iCountErrors++;
printerr( "Error_4y190! Incorrect number of files=="+filArr.Length);
}
names = new String[2];
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 !PLATFORM_UNIX // case-sensitive filesystem
iCountTestcases++;
if(Array.IndexOf(names, "aaabbcc") < 0) {
iCountErrors++;
printerr( "Error_48yg7! Incorrect name=="+filArr[1].Name);
}
#endif
strLoc = "Loc_3y8cc";
filArr = dir2.GetFiles("AAABB");
iCountTestcases++;
if(filArr.Length != 1) {
示例2: runTest
//.........这里部分代码省略.........
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, "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.Close();
fs2.Close();
fs3.Close();
fs4.Close();
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] = strArr[iLoop].Substring( strArr[iLoop].IndexOf(Path.DirectorySeparatorChar) + 1 );
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) {
iCountErrors++;
printerr( "Error_167yb! Incorrect name=="+strArr[2]);
}
iCountTestcases++;
if(Array.IndexOf(strArr, "TestFile2") < 0) {
iCountErrors++;
printerr( "Error_49yb7! Incorrect name=="+strArr[3]);
}
strArr = Directory.GetFileSystemEntries (dir2.Name , "*Dir2");
示例3: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
String strValue = String.Empty;
try
{
DirectoryInfo dir2;
String dirName = s_strTFAbbrev+"TestDir";
FileInfo[] filArr;
if(Directory.Exists(dirName))
Directory.Delete(dirName, true);
strLoc = "Loc_4y982";
dir2 = Directory.CreateDirectory(dirName);
filArr = dir2.GetFiles();
iCountTestcases++;
if(filArr.Length != 0) {
iCountErrors++;
printerr("Error_207v7! Incorrect number of directories returned");
}
strLoc = "Loc_2398c";
dir2.CreateSubdirectory("TestDir1");
dir2.CreateSubdirectory("TestDir2");
dir2.CreateSubdirectory("TestDir3");
FileStream fs1 = new FileInfo(dir2.FullName + "\\" +"TestFile1").Create();
FileStream fs2 = new FileInfo(dir2.FullName + "\\" +"TestFile2").Create();
FileStream fs3 = new FileInfo(dir2.FullName + "\\" +"Test.bat").Create();
FileStream fs4 = new FileInfo(dir2.FullName + "\\" +"Test.exe").Create();
fs1.Close();
fs2.Close();
fs3.Close();
fs4.Close();
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;
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(dirName+"\\TestFile1");
File.Delete(dirName+"\\TestFile2");
filArr = dir2.GetFiles();
iCountTestcases++;
if(filArr.Length != 2) {
iCountErrors++;
printerr( "Error_4y28x! Incorrect number of directories returned");
}
names = new String[2];
i = 0;
foreach( FileInfo f in filArr)
names[i++] = f.Name;
iCountTestcases++;
if(Array.IndexOf(names, "Test.bat") < 0) {
iCountErrors++;
printerr( "Error_0975b! Incorrect name=="+filArr[0].Name);
}
if(Array.IndexOf(names, "Test.exe") < 0) {
iCountErrors++;
printerr( "Error_928yb! Incorrect name=="+filArr[1].Name);
}
if(Directory.Exists(dirName))
Directory.Delete(dirName, true);
} catch (Exception exc_general ) {
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
//.........这里部分代码省略.........
示例4: runTest
//.........这里部分代码省略.........
printerr("Error_1234!!! INvalid number of file system entries count :: " + strArr.Length );
iCountErrors++ ;
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_1006! Unexpected exceptiont thrown: "+exc.ToString());
}
iCountTestcases++;
try {
strArr = Directory.GetFileSystemEntries(s_strTFPath);
if ( strArr == null || strArr.Length == 0 )
{
printerr("Error_2434!!! INvalid number of file system entries count :: " + strArr.Length );
iCountErrors++ ;
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_12321!!! Unexpected exceptiont thrown: "+exc.ToString());
}
dir2 = new DirectoryInfo( dirName );
dir2.Create();
strArr = Directory.GetFileSystemEntries ( dirName);
iCountTestcases++;
if(strArr.Length != 0) {
iCountErrors++;
printerr("Error_207v7! Incorrect number of directories returned");
}
strLoc = "Loc_2398c";
dir2.CreateSubdirectory("TestDir1");
dir2.CreateSubdirectory("TestDir2");
dir2.CreateSubdirectory("TestDir3");
FileStream fs1 = new FileInfo(dir2.ToString() + "\\" + "TestFile1").Create();
FileStream fs2 = new FileInfo(dir2.ToString() + "\\" + "TestFile2").Create();
FileStream fs3 = new FileInfo(dir2.ToString() + "\\" + "Test.bat").Create();
FileStream fs4 = new FileInfo(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] = strArr[iLoop].Substring( strArr[iLoop].IndexOf(Path.DirectorySeparatorChar) + 1 );
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.Close();
fs2.Close();
fs3.Close();
fs4.Close();
if(Directory.Exists(dirName))
Directory.Delete(dirName, true);
} catch (Exception exc_general ) {
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例5: WriteFile
private void WriteFile(StringBuilder fileContents, string fileName)
{
string mwlDirectory = ConfigurationManager.AppSettings["MWLDirectory"];
string mwlFilePath = mwlDirectory + "\\" + fileName + ".xml";
StreamWriter mwlFile = new FileInfo(mwlFilePath).CreateText();
mwlFile.Write(fileContents.ToString());
mwlFile.Close();
}