最近,项目中需要实现对文件夹中的地图照片进行重命名,然后将其放入对应级别下对应的行号文件夹中,对此用C#编写了一个程序来实现此功能。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class OpenFile : MonoBehaviour
{
public void Start()
{
string[] fileName = Directory.GetFiles("D:\\unityWork\\算法\\map");
for (int i = 0; i < fileName.Length; i++)
{
string[] arr = fileName[i].Split('\\');
string[] jpgNameArr = arr[4].Split(new char[] { '_','.'});
string path = "D:\\Map\\" + jpgNameArr[3] + "\\" + jpgNameArr[1] + "\\" + jpgNameArr[2] + ".jpg";
if (!File.Exists("D:\\Map\\" + jpgNameArr[3]))
{
Directory.CreateDirectory("D:\\Map\\" + jpgNameArr[3]);
}
if (!File.Exists("D:\\Map\\" + jpgNameArr[3] + "\\" + jpgNameArr[1]))
{
Directory.CreateDirectory("D:\\Map\\" + jpgNameArr[3] + "\\" + jpgNameArr[1]);
}
Debug.Log(path);
File.Move(fileName[i], path);
}
}
}
运行结果如下:
|