473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Looping through Filenames in the selected directory folder

HI,
I am new to C# and It might be a simple question.
I want to loop through filenames and ignore subfolder and its files. I have
to display all files names in the screen.

Please help me how to do it using C#.

thanks,


Oct 12 '06 #1
3 28436
You'll need to add "using System.IO;"

DirectoryInfo di = new DirectoryInfo(@"c:\");
foreach (FileInfo fi in di.GetFiles())
{
Console.WriteLine(fi.Name);
}
Console.ReadLine();

Kannan wrote:
HI,
I am new to C# and It might be a simple question.
I want to loop through filenames and ignore subfolder and its files. I have
to display all files names in the screen.

Please help me how to do it using C#.

thanks,
Oct 12 '06 #2
See Directory.GetFiles method in MSDN
http://msdn2.microsoft.com/en-us/library/07wt70x2.aspx. The sample is over
there

--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"Kannan" wrote:
HI,
I am new to C# and It might be a simple question.
I want to loop through filenames and ignore subfolder and its files. I have
to display all files names in the screen.

Please help me how to do it using C#.

thanks,

Oct 12 '06 #3
Thank you very much. It worked.

thanks,
"Michael Nemtsev" wrote:
See Directory.GetFiles method in MSDN
http://msdn2.microsoft.com/en-us/library/07wt70x2.aspx. The sample is over
there

--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"Kannan" wrote:
HI,
I am new to C# and It might be a simple question.
I want to loop through filenames and ignore subfolder and its files. I have
to display all files names in the screen.

Please help me how to do it using C#.

thanks,


Oct 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Steve Karnath | last post by:
Hi All, I would like to read the contents of folder and display filtered results in my page. Can someone point me in a direction just to get me started, Thanks. TIA Best Regards, Steve...
5
by: Krustov | last post by:
<?php $dirname = "."; $dh = opendir($dirname); while ($file = readdir($dh)) { if (is_dir ("$dirname/$file")) { print ""; } print "$file<br>";
2
by: rbutch | last post by:
guys, i need a little help with this. this is working (well sort of) i get the info, but it's not moving to a new line as it iterates thru the array and all of the fields are like ONE HUGE LONG...
2
by: Little Man | last post by:
any samples?? thanks
2
by: poldoj | last post by:
Hi all, Just wondering if is possible to get all filenames of files presents in a certain folder then put them in a array. Thanks
22
by: rtilley | last post by:
# Spaces are present before and after the XXX filename = ' XXX ' new_filename = filename.strip() if new_filename != filename: print filename Macs allow these spaces in file and folder...
2
by: Beagley | last post by:
I'm trying to give my user the ability to print multiple personell badges with one swoop. I can select multiple rows from my DataGridView object, but am having trouble looping through those rows to...
5
by: kulabhishek | last post by:
Hello, I have developed one application, and added it to right click pop-up menu of the folder. Whenever user right-clicks on folder and selects my application from pop-up menu, I want the path...
2
by: plotdevice | last post by:
I have a text file that has a frequently-changing list of filenames in it. exampleList.txt: fee.doc fye.doc foe.doc fum.doc ftangftang_ole_biscuitbarrel.doc
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.