Same method to export different txt files C# I have a basic method to export files, however I have several arrays to export and I need the files to have these names, I'm trying to make it by the enum list, however when I do it, the file isn't created and I'm wondering is there a way to combine the directory+name of array+.txt? Here's method that doesn't export nothing at all. Thank you for looking at the code.

enum exportByName { Client, Appointment, Address,Location,Historic }


        static string askPath()
        {
            var dir = "";

            do
            {
                Console.Clear();
                Console.Write("Insert path to export the txt file: ");
                dir = Console.ReadLine();
            } while (String.IsNullOrEmpty(dir));

            var userPath = Path.Combine(dir,Enum.GetName(typeof(exportByName),0),".txt");
            return userPath;
        }
I don't have much reputations to comment so trying to help for what I know and modified your code according to the need -

There are two issues I observed -


The below line in your code -



  var userPath = Path.Combine(dir,Enum.GetName(typeof(exportByName),0),".txt");


will generate the output "directory+name of array\.txt" instead of 
  "directory+name of array+.txt"


You mentioned the point saying "the file is not created", actually your code 
is just returning the path using Path.Combine you need to create file for each of the ENUM values using the File.WriteAllText method.


I have modified your code and placed below. Please check 

class Program
    {
        enum exportByName { Client, Appointment, Address, Location, Historic }


        static string askPath(int count)
        {
            var dir = "";

            do
            {
                Console.Clear();
                Console.Write("Insert path to export the txt file: ");
                dir = Console.ReadLine();
            } while (String.IsNullOrEmpty(dir));


            var userPath = Path.Combine(dir, Path.GetFileName((Enum.GetName(typeof(exportByName), count))) + ".txt");
            return userPath;
        }
        static void Main(string[] args)
        {

            for (int i = 0; i &lt; 4; i++)
            {
                var path = askPath(i);
                if (!File.Exists(path))  // if it doesn't exist, create

                    File.WriteAllText(path, "add text here");
            }
        }


    }


Hope this helps!