How do I retrieve all filenames matching a pattern in a directory? I tried this but it returns the full path instead of the filename.
Directory.GetFiles (path, "*.txt")
Do I have to manually crop the directory path off of the result? It's easy but maybe there is an even simpler solution :)
3. Type "dir /b > dirlist. txt" without quotes and press "Enter." This creates a list containing file names only. To include file sizes and dates, type "dir > dirlist.
Call opendir() function to open all file in present directory. Initialize dr pointer as dr = opendir("."). If(dr) while ((en = readdir(dr)) != NULL) print all the file name using en->d_name.
foreach (string s in Directory.GetFiles(path, "*.txt").Select(Path.GetFileName))
Console.WriteLine(s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With