c a simple implementation that determines whether the specified file exists

  • 2020-06-12 10:31:23
  • OfStack


private void button2_Click(object sender, EventArgs e)
        {
            if (File.Exists(@"E:\exists.txt"))
            {
                MessageBox.Show(" File exists ");
            }
            else
            {
                MessageBox.Show(" Without this file ");
            }
        }

Note: To use the File.Exists method, you need to refer to the System.Io namespace

Grammar:


public static bool Exists(string path)

parameter
path
Type: System.String
Files to check.

The return value
Type: ES24en. Boolean
true if the caller has the required permissions and path contains the name of an existing file; Otherwise false. This method also returns false if path is null, invalid path, or zero-length string. If the caller does not have sufficient permissions to read the specified file, an exception is not thrown and the method returns false, regardless of the existence of path.

note

The PATH should not be validated using the Exists method, which checks only for the existence of the file specified in path. Passing an invalid path to Exists returns false.

Note that between calling the Exists method and performing other operations on the file, such as Delete, other processes may do some processing on the file.

Allows the path parameter to specify relative or absolute path information. Relative path information is interpreted relative to the current working directory. To get the current working directory, see GetCurrentDirectory.

This method returns false if path describes a directory. Before determining whether the file exists, proceed from path


Related articles: