Skip to content

Instantly share code, notes, and snippets.

@AnomalousUnderdog
Created May 5, 2014 06:08
Show Gist options
  • Save AnomalousUnderdog/cd525d669ef93e1c5ceb to your computer and use it in GitHub Desktop.
Save AnomalousUnderdog/cd525d669ef93e1c5ceb to your computer and use it in GitHub Desktop.
A Unity editor script to get all filenames (and file sizes) in the project and save them in a .txt file as a list.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
namespace DldUtil
{
public class DumpFilenames
{
#if UNITY_EDITOR
[MenuItem("Window/Dump filenames of assets")]
public static void Dump()
{
string dumpFilename = EditorUtility.SaveFilePanel(
"Save dump to",
"",
"FileDump", "txt");
string folder = Application.dataPath;
Debug.Log("Dumping from: " + folder);
bool canceled = false;
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(dumpFilename));
System.IO.StreamWriter write = System.IO.File.CreateText(dumpFilename);
foreach (string file in TraverseDirectory.Do(folder))
{
canceled = EditorUtility.DisplayCancelableProgressBar("Dumping from " + folder, file, 0.5f);
if (canceled)
{
write.Write("\tCanceled by user\n");
Debug.Log("Dumping canceled by user");
break;
}
string fileRelativePath = file.Replace(folder, "");
long sizeInBytes = GetFileSizeInBytes(file);
write.Write(fileRelativePath + "\t" + sizeInBytes + "\n");
}
Debug.Log("Dumping complete");
write.Close();
EditorUtility.ClearProgressBar();
}
#endif
static long GetFileSizeInBytes(string filename)
{
FileInfo fi = new FileInfo(filename);
return fi.Length;
}
}
} // namespace DldUtil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment