- window
- function body code
private void getFileInfo(String path)
{
DirectoryInfo root = new DirectoryInfo(path);
FileInfo[] files = root.GetFiles();
foreach (FileInfo f in files)
{
bool exists = f.Exists; // Check whether the file exists in a given directory
string name = f.Name; // Get the name of the file
string fullName = f.FullName; // Get the full limited name of the file (complete path)
string extensioin = f.Extension; // Get the expansion name of the file
string directory = f.Directory.ToString(); // Get the directory where the file is located, the return type is Directoryinfo
string directoryName = f.DirectoryName; // The path of the directory where the file is located (complete path)
bool isReadOnly = f.IsReadOnly; // Whether the file is only read
string attributes = f.Attributes.ToString(); // Get or set the attributes of the specified file, and the return type is FileAttributes enumeration, which can be a combination of multiple values
string length = f.Length.ToString(); // Get the size of the file (number of bytes)
string creationTime = f.CreationTime.ToString(); // Get the time for the creation of the file
string lastAccessTime = f.LastAccessTime.ToString(); // Last visit to get the file
string lastWriteTime = f.LastWriteTime.ToString(); // Get the file last writing operation time
while (textBox2.Text.Length < 10)
{
textBox2.Text = "Check whether the file exists in a given directory:" + exists + "\r\n";
textBox2.Text += "File name:" + name + "\r\n";
///textbox2.appendtext (NVIRONMENT.NEWLINE); //
textBox2.Text += "Full limited name (complete path):" + fullName + "\r\n";
textBox2.Text += "File extension:" + extensioin + "\r\n";
textBox2.Text += "The path of the directory where the file is located (complete path):" + directoryName + "\r\n";
textBox2.Text += "Whether the file is read only:" + isReadOnly + "\r\n";
textBox2.Text += "File where the file is located:" + directory + "\r\n";
textBox2.Text += "File size:" + length + " B\r\n";
textBox2.Text += "File attributes:" + attributes + "\r\n";
textBox2.Text += "File creation time:" + creationTime + "\r\n";
textBox2.Text += "The last visit time of the file:" + lastAccessTime + "\r\n";
textBox2.Text += "The last writing operation time of the file:" + lastWriteTime + "\r\n";
}
}
}
function call
String path = @"E:\WinFormEx";
getFileInfo(path);
Running results