문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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();

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top