動作確認
Unity 5.1.1-f1 on MacOS X 10.8.5
ファイル関連の処理の練習。
- File.Exists()
- System.IO.FileInfo()
- fi1.Length
参考
http://dobon.net/vb/dotnet/file/filesize.html
CompareScript.cs
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEditor; // for ClearConsole()
using System.IO; // for File.XXX, FileInfo()
public class CompareScript : MonoBehaviour {
public InputField IF1; // filename1
public InputField IF2; // filename2
[MenuItem ("Tools/Clear Console %#c")]
static void ClearConsole() {
var logEntries = System.Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll");
var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
clearMethod.Invoke(null,null);
}
void compareFiles(string file1, string file2) {
if (File.Exists (file1) == false || File.Exists (file2) == false) {
Debug.Log("file not found");
return;
}
System.IO.FileInfo fi1 = new System.IO.FileInfo (file1);
System.IO.FileInfo fi2 = new System.IO.FileInfo (file2);
Debug.Log (fi1.Length.ToString ());
Debug.Log (fi2.Length.ToString ());
if (fi1.Length > fi2.Length) {
Debug.Log("file1 is larger than file2");
} else {
Debug.Log("file2 is larger than file1");
}
}
public void CompareClick() {
ClearConsole ();
compareFiles (IF1.text, IF2.text);
}
}