• 将一个目录下的某个格式的所有文件复制到另一个目录下


    其中39-50行是主要内容, 其他为扩展, 可根据自己的需求灵活运用

     1 using UnityEngine;
     2 using UnityEditor;
     3 using System.IO;
     4 
     5 /*
     6  * 此类为一些临时需要使用的工具
     7  */
     8 
     9 public class EditorTempTools
    10 {
    11     /// <summary>
    12     /// 将选中的文件目录中的jpg类型文件分拣并复制到外部文件夹
    13     /// </summary>
    14     [MenuItem("TempTool/临时工具_分拣扫描图到外部")]
    15     static void CreateIamgeObject_FindIdsToDataPath()
    16     {
    17         //要输出的文件存在的基础位置
    18         string basePath = Application.dataPath;
    19         basePath = basePath.Replace("Assets", "");
    20         basePath = basePath.Replace("/", @"") + @"\_Temp\_ShowImages";
    21 
    22         // 当前选中的文件目录
    23         string[] paths = Selection.assetGUIDs;
    24         foreach (var path in paths)
    25         {
    26             //获取选中的目录路径
    27             string pathIn = AssetDatabase.GUIDToAssetPath(path);
    28             Debug.Log(pathIn);
    29             //创建最终要保存的目录;(具体路径可根据自己的需要处理)
    30             string[] strs = pathIn.Split('/');
    31             string bookName = strs[strs.Length - 1];
    32             string pathOut = basePath + @"" + bookName;
    33             if (!Directory.Exists(pathOut))
    34             {
    35                 Directory.CreateDirectory(pathOut);
    36             }
    37 
    38             //相关目录信息
    39             DirectoryInfo directoryInfo = new DirectoryInfo(pathIn);
    40             //目录下所有的文件信息
    41             FileInfo[] fileInfos = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
    42             for (int i = 0; i < fileInfos.Length; i++)
    43             {
    44                 // 找到需要的文件
    45                 if (fileInfos[i].Name.EndsWith("_Show.jpg"))
    46                 {
    47                     Debug.Log("Name:" + fileInfos[i].Name);
    48                     //复制文件到最终存放位置(注意:如果该文件在最终位置已经存在,复制会报错;这里可以自己根据需求添加判断处理)
    49                     string pathFinal = pathOut + @"" + fileInfos[i].Name;
    50                     fileInfos[i].CopyTo(pathFinal);
    51                     Debug.Log(pathFinal);
    52                 }
    53             }
    54         }
    55     }
    56 }
  • 相关阅读:
    MySQL
    关于多因子选股模型的常见问题
    T100 GR 报表常见知识点 (含套版制作)
    Oracle Round 函式 (四捨五入)
    Oracle的字串處理
    改變帳款性質別以利排序沖帳才不會有問題,把19->17,把12->17
    財務月結結帳相關檢核程式
    t100 常用公用變數
    一、自动驾驶行业概述(第一课,新认识)
    第一章 软件体系结构概论
  • 原文地址:https://www.cnblogs.com/RainPaint/p/14846255.html
Copyright © 2020-2023  润新知