How to create a file or folder C#

 public static void DataLog(string message) {

            string path = @"C:\DataLog\\data\\";

            if (Directory.Exists(path)) {

                StreamWriter sw = null;

                try {

                    string logFile = DateTime.Now.ToString("ddMMyyyy") + "data.txt";

                    sw = new StreamWriter(@"C:\DataLog\\data\\" + logFile, true);

                    sw.WriteLine(DateTime.Now.ToString() + " : " + message);

                    sw.Flush();

                    sw.Close();

                }

                catch (Exception ex) {

                    Console.WriteLine("Failed! : Cannot write log . . .");

                }

            }

            else {

                DirectoryInfo di = Directory.CreateDirectory(path);

                Console.WriteLine("The directory was created successfully");

            }

        }



Rujukan

Directory.CreateDirectory Method - https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory?view=netcore-3.1

Ulasan

Catatan popular daripada blog ini

SISTEM PENGOPERASIAN KOMPUTER (OS)

APA ITU ASCII (AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE) ?

APA ITU EBCDIC (EXTANDENT BINARY CODEC DECIMAL INTERCHANGE CODE) ?

JENIS-JENIS SISTEM PENGOPERASIAN KOMPUTER

Router CP2001/RS980+ dan Cara config