PC Review


Reply
Thread Tools Rate Thread

Getting all files in Dir and Subdirs

 
 
augustesen@privat.tdcadsl.dk
Guest
Posts: n/a
 
      2nd Oct 2005
Hi

I am looking for a way to get all the files in a specific folder and
its subfolders (and the subfolders subfolders and so on).

Is there an easy way of doing this? Or do I have to go through every
single folder and subfolder?

Regards
Søren Augustesen

 
Reply With Quote
 
 
 
 
Arun
Guest
Posts: n/a
 
      3rd Oct 2005
Check out System.IO.Directory class
http://msdn.microsoft.com/library/de...classtopic.asp

GetDirectories
Directory.GetDirectories("c:\", "p*")

GetFiles
System.IO.Directory.GetFiles("foldername", "*.extension")

methods will help you to enumerate through directories and sub
directories and find files.

Hope this helps,
Cheers,
Arun.

 
Reply With Quote
 
augustesen@privat.tdcadsl.dk
Guest
Posts: n/a
 
      3rd Oct 2005
Hi Arun

I have looked into IO class, and I have tried using them.

I have tried the Directory.GetFileSystemEntries(dir) but that only
returns the dirs/files of the first sub layer. The problem is that I
don't know how many sublayers a folder has, so I can't just enumerate
through X numbers of directories and sub dirs to get the files.

What I am looking for is a command/rutine that will return all
filenames from all the sublayers in a folder.

Anyone know anything like this??

Regards
Søren Augustesen

 
Reply With Quote
 
Lonifasiko
Guest
Posts: n/a
 
      3rd Oct 2005
This example is targeted to Framework .NET, not for CF, but I think you
could try. It focuses on Directory and subfolders copying but I suppose
you could do a little change and obtain only filenames and directories.
Check it out and tell me please:

http://www.codeproject.com/csharp/xdirectorycopy.asp

Regards.

 
Reply With Quote
 
augustesen@privat.tdcadsl.dk
Guest
Posts: n/a
 
      6th Oct 2005
Hi

This code gives you all the files and subdirs in a given folder

public void ProcessDirectory(string targetDirectory)
{
// Handels the files found in the main folder
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
{
ProcessFile(fileName); //This function does what ever you want
to do with the files
}

// Finding the sub directories in the folder
string [] subdirectoryEntries =
Directory.GetDirectories(targetDirectory);

// For each subfolder this function is called again
foreach(string subdirectory in subdirectoryEntries)
{
AllDirNames.Add(subdirectory); //Add the Dir location to a
Global ArrayList
ProcessDirectory(subdirectory); //Calls this function againg
with the subdir as parmeter
}
}

Regards
Søren Augustesen


(E-Mail Removed) skrev:

> Hi
>
> I am looking for a way to get all the files in a specific folder and
> its subfolders (and the subfolders subfolders and so on).
>
> Is there an easy way of doing this? Or do I have to go through every
> single folder and subfolder?
>
> Regards
> Søren Augustesen


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pack directory with subdirs and files into file Piotrekk Microsoft C# .NET 2 11th Sep 2007 02:10 PM
How to Place DLLs in Subdirs Ecke Microsoft Dot NET 5 2nd Mar 2006 02:12 PM
Add all files and subdirs to a project (7.1) =?Utf-8?B?TmVpbA==?= Microsoft VC .NET 0 23rd Dec 2004 12:03 PM
Macro to enumerate subdirs and files in a directory! bookworm98 Microsoft Excel Programming 3 27th Jan 2004 08:48 AM
NETLOGON subdirs getting renamed Nick Payne Microsoft Windows 2000 File System 1 19th Nov 2003 05:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:03 PM.