473,408 Members | 2,405 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,408 software developers and data experts.

Seeking sample code to scan folders, files

I'm wanting to scan all folders and files under a specified path (e.g.
C:\Files). I know using System.IO I can use Directory.GetFiles to get a
list of files under a folder, but how do I get the name of the folder?

Is there any sample code out there that can kickstart me?

Thanks,
Ron
Dec 17 '06 #1
2 2542
Ronald S. Cook <rc***@westinis.comwrote:
I'm wanting to scan all folders and files under a specified path (e.g.
C:\Files). I know using System.IO I can use Directory.GetFiles to get a
list of files under a folder, but how do I get the name of the folder?
Get the name of *which* folder?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 17 '06 #2
Hi

As I understand you wanted to get the name of directories in side a
directory.
The following code illustrates the navigation of all files inside a
directory.. including directories.

class Program
{
static void Main(string[] args)
{

string path =
Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments);
DirectoryInfo rootDirInfo = new DirectoryInfo(path);

DisplayFilesOfDir(rootDirInfo);
Console.ReadLine();
}

public static void DisplayFilesOfDir(DirectoryInfo di)
{
DirectoryInfo[] dirInfo = di.GetDirectories();
foreach (DirectoryInfo dirInfoindex in dirInfo)
{
Console.WriteLine(dirInfoindex.Name);
DisplayFilesOfDir(dirInfoindex);
}

FileInfo[] fileInfos = di.GetFiles();

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

Hope this is helpful to you.

Thanks
-Srinivas.
Ronald S. Cook wrote:
I'm wanting to scan all folders and files under a specified path (e.g.
C:\Files). I know using System.IO I can use Directory.GetFiles to get a
list of files under a folder, but how do I get the name of the folder?

Is there any sample code out there that can kickstart me?

Thanks,
Ron
Dec 17 '06 #3

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

Similar topics

2
by: s_m_b | last post by:
<script language="javascript" src="/inc/js_popup_window.js" type="text/javascript"></script> <script language =" JavaScript" type="text/javascript"> function openScanWindow () {...
2
by: Anita C | last post by:
Hi, How do I associate or map a specific column in a datatable to a particular element present in an xml document - to read into a datatable as well as write from the datatable to the xml element?...
1
by: Nut Cracker | last post by:
Hello, If anyone can point me to a good ASP based Control Panel for IIS5, I would be much obliged. I hacked together an ASP site for file uploads and sharing. Its very simple, and basically...
0
by: Eric | last post by:
We've got a fairly large legacy ASP site, consiting of one main website with a lot of sub-folders organized in a tree under the main site. We don't use IIS Application/Virtual directories other...
3
by: =?Utf-8?B?Tkg=?= | last post by:
Hi, I am looking for some code that would scan a folder structure and files in those folders and display them on a web page so that people can click on the file links and open the files. There...
3
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hi, does anyone know if I can scan a subdirectory using wildcards? I do not see a way to do this using: string folder = @"C:\INPUT\CUSTOMERS\ID???BC.*" DirectoryInfo di = new...
2
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I have some code (given to me), but I don't know alot about ASP, so I was hoping someone here can help. The code below will scan a folder and subfolder with a date/time input and...
8
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I have some code (given to me), but I don't know alot about ASP, so I was hoping someone here can help. Running on Win 2008 server. The code below will scan a folder and subfolder...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.