using UnityEngine;
using System.Collections;using System.IO;/// <summary>/// Move file./// 移动文件,/// </summary>public class MoveFile : MonoBehaviour {// Use this for initialization
void Start () { Debug.Log (Application.persistentDataPath); //创建文件夹 //CreateFolder(Application.persistentDataPath,"test");//移动文件
//MoveFileWithXML (Application.dataPath + @"/TestXml.xml" , Application.persistentDataPath+"/李佳/"+@"/TestXml.xml");//复制文件
//CopyFileWithXML(Application.dataPath + @"/TestXml.xml" , Application.persistentDataPath+"/李佳/"+@"/TestXml.xml",true);//查看文件夹是否存在
//FolderIsExist("李佳"); //bool k = fileOrfodlerExists (Application.persistentDataPath, "D.assetbundle", true); //Debug.Log (k);}
// Update is called once per frame
void Update () { }#region 创建文件夹
private void CreateFolder(string folderPath,string folderName) { Directory.CreateDirectory(folderPath+@"/"+folderName); //Directory.CreateDirectory(Application.persistentDataPath+@"/李佳"); } #endregion#region 判断文件夹是否存在
//判断文件夹 private void FolderIsExist(string folderName) { if (Directory.Exists (Application.persistentDataPath + "/"+folderName)) { Debug.Log ("文件夹存在"); } else { Debug.Log ("文件夹不存在"); } } //判断文件和文件夹结合 //true----文件 false-----文件夹 public static bool fileOrfodlerExists(string path,string fileName,bool fileOrfodler) { if (fileOrfodler == true) { //判断文件是否存在 if (File.Exists (path +"/"+ fileName)) { Debug.Log (fileName + "---文件存在"); return true; } else { Debug.Log (fileName + "---文件不存在"); return false; } } else { //判断文件是否存在 if (Directory.Exists (path +"/"+ fileName)) { Debug.Log (fileName + "---文件夹存在"); return true; } else { Debug.Log (fileName + "---文件夹不存在"); return false; } } } #endregion#region 复制文件方法 文件复制方法:File.Copy
//A_dataPath---原始路径,B_dataPath----需要移动到的路径,overwrite---是否覆盖同名文件 public static void CopyFileWithXML(string A_dataPath,string B_dataPath,bool overwrite) { File.Copy(A_dataPath,B_dataPath,true); } #endregion#region 文件移动方法:File.Move
//A_dataPath---原始路径,B_dataPath----需要移动到的路径 //磁盘位置要相同否则出错 private void MoveFileWithXML(string A_dataPath,string B_dataPath) { if (!File.Exists (Application.persistentDataPath + "/李佳/" + @"/TestXml.xml")) { File.Move (A_dataPath, B_dataPath); } else { Debug.Log ("文件存在"); } } #endregion
}