473,385 Members | 1,587 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,385 software developers and data experts.

Is there a way to get a list of file names from within a directory

I want to display a list of filenames that exist in a certain
directory. How do I go about loading this list?

Jun 7 '06 #1
3 1758
jpabich wrote:
I want to display a list of filenames that exist in a certain
directory. How do I go about loading this list?


Look into:
System.IO.Directory
(http://msdn2.microsoft.com/en-us/lib...directory.aspx)
System.IO.DirectoryInfo
(http://msdn2.microsoft.com/en-us/sys...ctoryinfo.aspx)

string[] files = System.IO.Directory.GetFiles(@"c:\directory");

Dan Manges
Jun 7 '06 #2
See DirectoryInfo/FileInfo classes in MSDN

public static void Main()
{
// Create a reference to the current directory.
DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
// Create an array representing the files in the current directory.
FileInfo[] fi = di.GetFiles();
Console.WriteLine("The following files exist in the current
directory:");
// Print out the names of the files in the current directory.
foreach (FileInfo fiTemp in fi)
Console.WriteLine(fiTemp.Name);
}
}

"jpabich" wrote:
I want to display a list of filenames that exist in a certain
directory. How do I go about loading this list?


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

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

Jun 7 '06 #3

"jpabich" <jp*****@eisincorporated.com> wrote...
I want to display a list of filenames that exist in a certain
directory. How do I go about loading this list?


If it's just in order to "display" the list of filenames, you can simply do:

DirectoryInfo dirInfo = new DirectoryInfo("directoryPath");
FileInfo[] fileInfos = dirInfo.GetFiles();

foreach (FileInfo fi in fileInfos)
{
Console.WriteLine(fi);
}

If you want to display it in some other way, you can use each FileInfo as
you like, e.g. to extract only the short filenames as strings, as the above
will display the full path of the files.

/// Bjorn A
Jun 7 '06 #4

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

Similar topics

3
by: kakaz | last post by:
Hi All there! I am quite new in MS SQL administration so let me explain how it work on Your instances of SQL Servers. We have several DTS packages on our server, all of them managed on some...
0
by: Tess | last post by:
Hi, Long time reader, first time poster... Any help is appreciated. I have a few questions regarding Winform controls embedded within an html page. For more info please see the appendix. Now,...
8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
1
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double...
2
by: xeshu | last post by:
HelowWw fellow programmers :) I have a web application that opens a pdf file. Very simple indeed. However the file name is not known. The file has to be found by first searching the list of all...
4
by: thoseion | last post by:
Hi, I am trying to get a program working whereby directory and file names are read into a list. I have been given the original list structure - it appears that the directory names should be added...
6
by: Shawn Minisall | last post by:
I'm writing a game that uses two functions to check and see if a file called highScoresList.txt exists in the main dir of the game program. If it doesn, it creates one. That part is working fine. ...
8
by: dmp | last post by:
What are Linked list? Please somebody show some ready made programs of linked list
3
by: Al Moodie | last post by:
I have a directory with 200 sub directories in it. How do I create a list of the sub directory names? I know how create a list of all the files in a directory: opendir(DIR, $dirname) or die...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...

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.