FileInfo theFile = new FileInfo( "c:\windows\a.txt");
if( theTile.Exists )

解决方案 »

  1.   

    FileInfo theFile = new FileInfo("c:\\windows\\a.txt");
    if(theFile.Exists)
    {
      MessageBox.Show("存在");
    }
      

  2.   

    DirectoryInfo theFolder = new DirectoryInfo(@"C:\Windows");
    DirectoryInof[] folderArray = theFolder.GetDirectories();
    foreach( DirectoryInfo folder in folderArray)
    {
      FileInfo[] fileArray = folder.GetFiles();
      foreach( FileInfo file in fileArray )
      {
         if( fileInfo.Name == "a.txt" )
          MessageBox.Show( "Exist");
         break;
      }
    }
      

  3.   

    DirectoryInfo theFolder = new DirectoryInfo(@"C:\Windows");
    DirectoryInof[] folderArray = theFolder.GetDirectories();
    foreach( DirectoryInfo folder in folderArray)
    {
      String path = folder.Name + "\a.txt";
      FileInfo file = new FileInfo(path);
      if(file.Exists)
           MessageBox.Show( "Exist");
       break;
      }
    }
      

  4.   

    DirectoryInfo theFolder = new DirectoryInfo(@"C:\Windows");
    DirectoryInof[] folderArray = theFolder.GetDirectories();
    foreach( DirectoryInfo folder in folderArray)
    {
      String path = folder.Name + "\a.txt";
      FileInfo file = new FileInfo(path);
      if(file.Exists)
           MessageBox.Show( "Exist");
       break;
      }
    }
      

  5.   

    if (File.Exist("文件路径"))
    MessageBox.Show("该文件存在");
      

  6.   

    DirectoryInfo Folder = new DirectoryInfo("C:\\Windows");
    DirectoryInof[] folderArray = Folder.GetDirectories();
    foreach( DirectoryInfo folder in folderArray)
    {
      String p = folder.Name + "\\a.txt";
      FileInfo file = new FileInfo(p);
      if(file.Exists)
           MessageBox.Show( "存在!");
       break;
      }
    }
      

  7.   

    using System.IO;
    -------------------
    FileInfo aFile = new FileInfo(@"c:\glf\mynote.txt");
    if(aFile.Exists)
    {
      MessageBox.Show("存在");
    }
    else
    {
      MessageBox.Show("不存在");
    }
      

  8.   

    same to songlian(雨)各位仁兄干嘛要把问题处理得这么复杂?
      

  9.   

    如:现在要判断C:\Windows的目录下(包括子目录)是否存在个a.txt文件,如何写?
                                     *************
    请各位看清~~
      

  10.   

    如果该文件存在,则为 true;如果该文件不存在或如果该文件是目录,则为 false。using System;
    using System.IO;public class ExistsTest {
        public static void Main() {        string neFile = "nonexistentfile";        // open an existing file, or create a new one
            FileInfo fi = new FileInfo(neFile);        DetermineExists(fi, neFile);        neFile = "a.txt";        // create a file, so it exists
            fi = new FileInfo(neFile);
            FileStream fs = fi.Create();        DetermineExists(fi, neFile);        // close the file so it can be deleted
            fs.Close();        // delete the file
            try {
                fi.Delete();
                Console.WriteLine("The file '{0}' was deleted successfully", fi.Name);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }    private static void DetermineExists( FileInfo fi, string fileName ) {        // figure out if the file exists or not
            if (fi.Exists)
                Console.WriteLine("The file '{0}' exists in the specified directory", fileName);
            else
                Console.WriteLine("The file '{0}' does not exist in the specified directory", fileName);
        }
    }