Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
Save multiple directory paths to file and upon restart read from it to populate variables

I have a program which in order to function needs the user to input two directories (e.g. the Desktop and Picture directory). This works, but upon closing and relaunching the program, the user needs to re-enter the directories, as the program does not remember the directories from the last time it ran. Obviously.

Now my plan was to create a file to which the program writes the directories so that once the user launches the program it checks if the file exists and if so reads it and gets the two directories it needs.

I tried creating a plain .txt, but as there are two directories and either one or the other can be written to the .txt first it was hard to read from it and get the correct directory. To visualize my .txt can look like this:

C://Dir1 C://Dir2 See here

or

C://Dir2 C://Dir1 See here

depending on which directory the user selected first.

See here

Tl;Dr I want to save two directories for consequent launches of the program, but when reading the two directories I need to be able to know which directory is which.

I am working with .NET Core 3.1

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

either one or the other can be written to the .txt first

This is a wrong assumption. You decide in your code in which order they are written and you always write both of them, never one of them only.

Example code for writing:

string a = null;
string b = "c:\\something";
File.WriteAllText("myconfig.txt", a+ "\r\n" + b);

Example code for reading:

string[] filecontent = File.ReadAllLines("myconfig.txt");
a = filecontent[0];
if (a==string.Empty) a = null;
b = filecontent[1];
if (b==string.Empty) b = null;
Console.WriteLine(a);
Console.WriteLine(b);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda