---
title: "How can I read all files in a directory to an array using C#?"  
description: "How can I read all files in a directory to an array using C#?"  
author: "Lady Bird Johnson"  
published: 2013-10-05  
updated: 2013-10-05  
canonical: https://www.mindstick.com/forum/1619/how-can-i-read-all-files-in-a-directory-to-an-array-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How can I read all files in a directory to an array using C#?

I have a folder D:\MyDirectory that is [full](https://www.mindstick.com/articles/12893/experience-the-full-power-of-suitecrm) of tab-delimited [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) [files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud), but the number of files is unknown at any given time. How Can I read and [store](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store) the names of the text files in the MyDirectory [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp) into an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net)?

## Replies

### Reply by Hank Greenberg

You should use System.IO.Directory.GetFiles() and if know the file extension then you should use use System.IO.Directory.GetFiles(@"C:\ MyDirectory*.txt")


---

Original Source: https://www.mindstick.com/forum/1619/how-can-i-read-all-files-in-a-directory-to-an-array-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
