- Home /
Create text file of folder structure via EditorScript
[MenuItem("Assets/AssetBundle/StandaloneWindows")]
static void ExportBundleStandaloneWindows()
{
//Windowws
string bundlePathWin = _remotePath + "StandaloneWindows";
if (!Directory.Exists(bundlePathWin))
Directory.CreateDirectory(bundlePathWin);
BuildPipeline.BuildAssetBundles(bundlePathWin, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
so this script is creating the assetbundle i need. All working. Is it possible to create a .txt-file or a .json in the same method to list content of given directory? I've literally searched the whole web for it. I've tried everything and either I'm just not advanced enough to get it or I'm missing some vital information.
Answer by SkaredCreations · Sep 12, 2018 at 10:19 AM
The following example will create a text file in the bundlePathWin (from your example below) with the list of files existing in that folder:
MenuItem("Assets/AssetBundle/Index/StandaloneWindows")]
static void ExportBundleStandaloneWindowsIndex()
{
string bundlePathWin = _remotePath + "StandaloneWindows";
string folderContent = "";
if (Directory.Exists(bundlePathWin))
{
var allFiles = Directory.GetFiles(bundlePathWin, "", SearchOption.AllDirectories);
foreach (string filePath in allFiles)
{
// Skip the index file
if (filePath.EndsWith("all_content.txt"))
folderContent += filePath + "\n";
}
}
string contentFilepath = Path.Combine(bundlePathWin, "all_content.txt");
File.WriteAllText(folderContent);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612174414im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there a some sort of OnBuild() event for the editor? 1 Answer
Modify "Builds Settings/Scenes to Build" in Script 2 Answers
Cancel build in PostProcessScene? 0 Answers
PostProcessScene called before building the scene? 0 Answers
Custom DLL: mybuildcode.dll is identical to mybuildpluseditor.dll, but does not work in build 0 Answers