Read files and automatically put in the desired line;

-1

I have several files in a folder: 01.PNG, 02.PNG, 05.PNG, some of the files do not have (04.PNG, 03.PNG).

What would be the easiest way to write a text document where each filename would be written to the same line number:

So:

01.PNG
02.PNG


05.PNG

NOTE THAT THE MISSING FILES, the lines have just been skipped!

    
asked by anonymous 22.01.2018 / 13:59

2 answers

1

In C # I use the following code to read the files, sorted by creation date:

using System.IO;

string path=@"C:\ExampleArquivos"; \caminho onde estão os arquivos

var files = new DirectoryInfo(pathexportacao).GetFiles().OrderBy(x => x.CreationTime).ToList();

After reading the files, you can perform a foreach to save the name in a txt.

string path=@"C:\Example\Example.txt";

foreach (var file in files)
        {  
            File.Create(path).Dispose();
            using(TextWriter tw = new StreamWriter(path))
            {
              tw.WriteLine(file.Name);
              tw.Close();
             }
        }
    
22.01.2018 / 14:49
0

As you said you will use excel, I recommend developing this in VBA. It will not run away from the concept of your problem and is a language with much (very much) support from people on the internet.

I do not program in VBA, but you understand the basis of it will have no secret ...

novo: arquivo
se > arquivo existe 
imprime: nome, quebra a linha
se > arquivo não existe
imprime: quebra linha, quebra linha
    
22.01.2018 / 14:23