Returns the path that contains the file name. and then intercept the filename.
Such as:
string[] Filenames=directory.getfiles (path);
For (string files in filenames)
{
Response.Write (Files.replace (Path, ""));
}
Method Two:
DirectoryInfo dir = new DirectoryInfo (@ "C:data");
fileinfo[] Finfo = Dir.getfiles ();
string fnames = String.Empty;
for (int i = 0; i < finfo.length; i++)
{
Fnames + + finfo[i].name + "<br>";
}
Response.Write (Fnames);
Method Three
///<summary>
///Get all file names under the specified folder
///</summary>
///<param name= "foldername" > Specify folder names , absolute path </param>
///<param name= "filefilter" > file type filtering, according to the file suffix name, such as: *,*.txt,*.xls</param>
/// <param name= "Iscontainsubfolder" > whether to include subfolders </param>
///<returns>arraylist Array, for all required file path names < /returns>
public static ArrayList Getallfilesbyfolder (String foldername, String Filefilter,bool Iscontainsubfolder)
{
ArrayList resarray = new ArrayList ();
string[] files = directory.getfiles (foldername, F Ilefilter);
for (int i = 0; i < files.length; i++)
{
Resarray.add (files[i]);
}
if (iscontainsubfolder)
{
string[] folders = directory.getdirectories (foldername);
for (int j = 0; J < Folders.length; J + +)
{
//Traverse all folders
ArrayList temp = Getallfilesbyfolder (Folders[j], filefilter, iscontainsubfolder);
Resarray.addrange (temp);
}
}
return resarray;
}
///<summary>
///gets all the file names under the specified folder, does not filter file types
///</summary>
///<param name= "foldername" > Specify folder name, absolute path </param>
///<param name= "Iscontainsubfolder" > whether to include subfolders </param>
///< Returns>arraylist Array, </returns> for all required file path names;
public static ArrayList Getallfilesbyfolder (string FolderName, BOOL Iscontainsubfolder)
{
return Getallfilesbyfolder (foldername, "*", Iscontainsubfolder);
}