Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda