Getting the list of files in a folder in C3 is very easy. The contents of the folder (both files and subfolders) are returned as an array of FileInfo objects. Fortunately, this object has a flag to check whether it is a file or folder and then you can process them accordingly.
One useful technique would be to recurse through the folder structure, which would entail, for each folder in the list, calling the function again to get the files below that.
public void processFolder(string folder)
{
DirectoryInfo dirInfo = new DirectoryInfo(folder);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo file in files)
{
if (file.Attributes = FileAttributes.Directory)
{
//we have a directory
processFolder(file.FullName);
}
else
{
//do whatever we need to with the file
}
}
}
Related posts:
- Compression using C# You would have thought that .NET, with its vast libraries...
- Writing a family tree application in C# – Importing a Gedcom file – Part 1 In my previous post in this series, I introduced the...
- Astronomical calculations in C#: Handling degrees, minutes and seconds A lot of astronomy is based on mapping positions of...
- Vectors in C# A vector is simply a 1-dimensional array of numbers that...
- Astronomical calculations in C#: Right ascension Before I move on to other stuff, let us talk...
Related posts brought to you by Yet Another Related Posts Plugin.
Serge Meunier is a software developer living in Cape Town, South Africa. He loves programming, fencing, philosophy, feeding his internet addiction, and, of course, dogs.
Comments