---
title: "How to read all files inside a specific folder"  
description: "How to read all files inside a specific folder"  
author: "Anupam Mishra"  
published: 2016-01-22  
updated: 2016-01-22  
canonical: https://www.mindstick.com/forum/33912/how-to-read-all-files-inside-a-specific-folder  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 1 minute  

---

# How to read all files inside a specific folder

Hi everyone,I want to [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) all [file name](https://www.mindstick.com/interview/2597/can-you-have-two-files-with-the-same-file-name-in-gac) which is [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) in my specific folder i.e. "**d:/Anupam Mishra**". i [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to use following [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) but i can not get correct output. Please give me a solution.Code:

```
         try              {               foreach (string dir in Directory.GetDirectories("d:"))                   foreach (string fileName in Directory.GetFiles("d:/Anupam Mishra"))                       Console.WriteLine(fileName );                  }              }           catch (System.Exception ex)            {               Console.WriteLine(ex.Message);            }                {                    {                    }
```

\

Thank You.

## Replies

### Reply by Anupam Mishra

\

If we are using this code . it will working on above problem:

\

```
class Program    {        static void DirSearch()        {            try            {                foreach (string file in Directory.GetFiles("d:\\Anupam Mishra", "*.txt"))                {                    Console.WriteLine(file);                }            }            catch (System.Exception excpt)            {                Console.WriteLine(excpt.Message);            }        }        static void Main(string[] args)        {            DirSearch();            Console.ReadKey();        }    }
```

**Output:**

**\**//retrieve all text files which is inside a specified directory.


---

Original Source: https://www.mindstick.com/forum/33912/how-to-read-all-files-inside-a-specific-folder

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
