Click here to Skip to main content
15,881,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi exports,
I am facing a difficulty. I want to list all the files in a folder. Let's say: "D:\bin". How can I get all these files names and write them to Excel files? I am no way to figure. How about your ideas? Thanks in Advance. I am using C#.NET here. Any methods to call in that case or API?
Regards
Posted
Updated 20-May-12 19:34pm
v2

To get a list of files :
C#
string[] files = Directory.GetFiles(@"D:\bin", "*.*");


To write to Excel try using a library like : http://epplus.codeplex.com/[^]
 
Share this answer
 
Comments
Pandvi 21-May-12 1:39am    
Alright. I should have thought about string array. I am so ... Thank you.
Mehdi Gholam 21-May-12 1:45am    
Cheers.
VJ Reddy 22-May-12 3:50am    
Good answer. 5!
Mehdi Gholam 22-May-12 4:39am    
Thanks VJ!
In short:
To list all the files in a folder or directory using the .NET Framework's methods in the System.IO namespace and the C# programming language, the framework provides powerful methods on the Directory class that can help you list files on the filesystem. The Directory.GetFiles method allows you to get a string array of the file names.
Please refer:
C# Directory.GetFiles[^]

This example shows how to get list of file names from a directory (including subdirectories). You can filter the list by specific extension.
Get Files from Directory [C#][^]
 
Share this answer
 
v2
Comments
Pandvi 21-May-12 1:39am    
Good, Many thanks.
Prasad_Kulkarni 21-May-12 1:40am    
You're welcome!
P.Salini 21-May-12 1:40am    
My 5
Prasad_Kulkarni 21-May-12 1:40am    
Thank you P.Salini!
Pandvi 21-May-12 1:45am    
:) I am too "stupid" to forget the ease of writing string to excel.
Hi
see project

MP3-Rearrange

See class RecursiveIO. That will search a directory tree. Remove the call to method subRecurse in method subRecurse if you want the specified directory only.

You can override method ProcessFileName to write to a comma separated text file which Excel can easily import.

Best

John Orendt
 
Share this answer
 
if the problem is not solved do let me know i have code for this. I did this thing few days ago
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900