0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unity > fileIO > File.Exists() / System.IO.FileInfo() / fi1.Length

Last updated at Posted at 2015-08-14
動作確認
Unity 5.1.1-f1 on MacOS X 10.8.5

ファイル関連の処理の練習。

  1. File.Exists()
  2. System.IO.FileInfo()
  3. 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);
	}
}

Scene1_unity_-150814_fileBattler-PC__Mac___Linux_Standalone__Personal.jpg

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?