How can I create text files

Hi I want to leave notes to myself but only file that ı can create for writing is c# file. Is there any way to create text file or notepad in unity

I wrote this script a while ago for someone who asked the same question:

#if UNITY_EDITOR
using System.IO;
using UnityEditor;

public static class CreateTextFile
{
    [MenuItem("Assets/Create/MISC/New Text File", priority = 100)]
    private static void CreateNewTextFile()
    {
        string folderGUID = Selection.assetGUIDs[0];
        string projectFolderPath = AssetDatabase.GUIDToAssetPath(folderGUID);
        string folderDirectory = Path.GetFullPath(projectFolderPath);

        using (StreamWriter sw = File.CreateText(folderDirectory + "/NewTextFile.txt"))
        {
            sw.WriteLine("This is a new text file!");
        }
       
        AssetDatabase.Refresh();
    }
}
#endif

Mind you there are better ways to compile information about your project.

4 Likes

to make it simpler from @spiney199 code, just this will create the file

    using (StreamWriter sw = new StreamWriter(Application.dataPath+ "/NewTextFile.txt",true))
        {
            sw.WriteLine("This is a new text file!");
        }
1 Like

Why though? My code creates it in the currently viewed folder, which I imagine is what you want 99% of the time.

1 Like

just saying to simplify, can be used out of unity editor and any path, and any way

1 Like