How can I get all filenames of a directory (and its subdirectorys) without the full path? Directory.GetFiles(...) returns always the full path!
You can get the files name of particular directory using GetFiles()
method of the DirectoryInfo
class.
Here are sample example to list out all file and it's details of particular directory
System.Text.StringBuilder objSB = new System.Text.StringBuilder();
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo("d:\\");
objSB.Append("");
objSB.Append("FileName " +
"Last Access " +
"Last Write " +
"Attributes " +
"Length(Byte) Extension ");
foreach (System.IO.FileInfo objFile in directory.GetFiles("*.*"))
{
objSB.Append("");
objSB.Append("");
objSB.Append(objFile.Name);
objSB.Append(" ");
objSB.Append("");
objSB.Append(objFile.LastAccessTime);
objSB.Append(" ");
objSB.Append("");
objSB.Append(objFile.LastWriteTime);
objSB.Append(" ");
objSB.Append("");
objSB.Append(objFile.Attributes);
objSB.Append(" ");
objSB.Append("");
objSB.Append(objFile.Length);
objSB.Append(" ");
objSB.Append("");
objSB.Append(objFile.Extension);
objSB.Append(" ");
objSB.Append(" ");
}
objSB.Append("
");
Response.Write(objSB.ToString());
This example display list of file in HTML table structure.