Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!