-1

Please can you help me how can i get informations about files in folder? Because i need exactly get trace from all files in folder.

For Examples:

Trace is:

G:/Program Files/test/vse - here is all image files what i need

I created list where i will save trace from this files. And i need automatically get trace from individual files in the folder.

Important is that all files have individual name "1 - 100.jpg" if all will be work correctly so this will be out informations:

I need this result:

List<string> trace = new List<string>() which contains all trace with his name about file.

For Example:

G:/Program Files/test/vse/1.jpg
G:/Program Files/test/vse/2.jpg
G:/Program Files/test/vse/3.jpg
...
...
G:/Program Files/test/vse/100.jpg

I really thx for all answers.

Radek Tarant
  • 227
  • 1
  • 5
  • 14
  • Can you show the code you have written so far to solve that problem? Also, please review your tags: Why do you think a `StreamReader` or a `FileReader` is required to solve your problem? – O. R. Mapper May 11 '14 at 12:29
  • 2
    Have you checked out http://msdn.microsoft.com/en-us/library/dd997370%28v=vs.110%29.aspx – CharlesNRice May 11 '14 at 12:29
  • Explain "trace" and "automatically get trace to individual files in the folder". – CodeCaster May 11 '14 at 12:30
  • O. R. Mapper - problem is that i havent any code for this functions because i dont know how do it. Because i dont know how can i get all trace from individual files in folder add to list. CodeCaster - I edited it. – Radek Tarant May 11 '14 at 12:33
  • Do you mean a "file path" by a "trace"? It looks like it based on your example. – Ondrej Janacek May 11 '14 at 12:54
  • possible duplicate of [How to recursively list all the files in a directory in C#?](http://stackoverflow.com/questions/929276/how-to-recursively-list-all-the-files-in-a-directory-in-c) – CodeCaster May 11 '14 at 19:20

3 Answers3

1

Try something like this:

var listOfFiles = new  List<String>();
        string [] fileEntries = Directory.GetFiles(targetDirectory);
        foreach(string fileName in fileEntries)
            {
                lisOfFiles.Add(fileName);
            }

for more info look here : http://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx

qamar
  • 1,437
  • 1
  • 9
  • 12
  • I will try it and write feedback from it – Radek Tarant May 11 '14 at 12:32
  • 2
    Code for copy-and-pasting may solve the current problem of the OP, but does not necessarily help them understand how to solve similar problems, and less so will future visitors with similar, yet not the same problem benefit from this answer. Note that links can go dead, so it would be helpful to add an explanation of what you are doing right in the answer as well. – O. R. Mapper May 11 '14 at 12:32
  • @mapper or soemthing, See i added the link. you should see this link is from msdn they dont usually go dead. i did not claim this code is mine!!! – qamar May 11 '14 at 12:34
  • I'd say the code is self explanatory enough that it doesn't need much explanation. – Evan Trimboli May 11 '14 at 12:35
  • He also added a little typo to get a bit of a challenge to the C&P'ing ;-) – TaW May 11 '14 at 12:36
0

Use the static methods Directory.GetFiles that return an array of string containing the path of your files.

Additionally, you can use the extension method ToList() to convert the collection to a List<string>.

var files = Directory.GetFiles(directoryPath).ToList();
Jämes
  • 6,945
  • 4
  • 40
  • 56
0

The FileInfo provide a lot of information about files, so you could convert it to Fileinfo:

 var files = Directory.GetFiles(Path.Combine(directoryPath)).Select(x => new FileInfo(x));

The FileInfo has Name attribute that return the File name also has an Extension property which return the file extensions and so on.

Vajda Endre
  • 1,512
  • 1
  • 16
  • 26