Unity3D C#脚本获取指定目录指定类型文件并改名

目录

一.目的

1.想将这个路径下面的mp4文件修改为自己设置的名字

二.参考

1.Unity3D C#脚本获取指定目录所有指定类型文件并改名

1.C#实现文件改名

三.操作:1:完成:能单个改名字

1.运行结果:完成,能将文件名字修改为自己指定的名字

1.代码:将整个文件夹路径传入进入


一.目的

1.想将这个路径下面的mp4文件修改为自己设置的名字

xzy [record]宸茬敓鎴愪竴涓綍鍍忔枃浠?: /storage/emulated/0/Android/data/com.daniulive.RescueRTSPPlayer/files/MyRecord/2010-02-19-21-46-48-1.mp4

 

二.参考

1.Unity3D C#脚本获取指定目录所有指定类型文件并改名

https://www.jianshu.com/p/cc3d98893e38

  1. 放弃,不合适使用

 

1.C#实现文件改名

 http://blog.sina.com.cn/s/blog_4e3fdbf7010008n5.html

  1. good:非常好,将字符串处理解释的很好
  2.  // 获取当前路径下全部文件名         String[] files = Directory.GetFiles(Environment.CurrentDirectory);
  3. // 最后一个"\"             int lastpath = filename.LastIndexOf("/");     //有的是'/'路劲
  4.     // 最后一个"."               int lastdot = filename.LastIndexOf(".");
  5.     // 纯文件名字长度            int length = lastdot-lastpath-1;
  6.     // 文件目录字符串 xx\xx\xx\               String beginpart = filename.Substring(0, lastpath+1);
  7.     //  纯文件名字               String namenoext = filename.Substring(lastpath+1, length);
  8.     //   扩展名                  String ext = filename.Substring(lastdot);

 

三.操作:1:完成:能单个改名字

1.运行结果:完成,能将文件名字修改为自己指定的名字

1.代码:将整个文件夹路径传入进入

  1.  // 获取当前路径下全部文件名         String[] files = Directory.GetFiles(Environment.CurrentDirectory);
  2. // 最后一个"\"             int lastpath = filename.LastIndexOf("/");     //有的是'/'路劲
  3.     // 最后一个"."               int lastdot = filename.LastIndexOf(".");
  4.     // 纯文件名字长度            int length = lastdot-lastpath-1;
  5.     // 文件目录字符串 xx\xx\xx\               String beginpart = filename.Substring(0, lastpath+1);
  6.     //  纯文件名字               String namenoext = filename.Substring(lastpath+1, length);
  7.     //   扩展名                  String ext = filename.Substring(lastdot);
    /// <summary>
    /// 功能:设置更改 录像文件名字
    /// </summary>
    /// <param name="_strFilePath">录像完毕后,由大牛做的安卓响应的回调事件</param>
    /// <returns></returns>
    int SetChangeRecorderFileName(string _strFilePath)
    {
        string FullPath = _strFilePath;

        // 最后一个"/" 占据整个路径字符串的索引
        int lastpath = FullPath.LastIndexOf("/");
        Debug.Log("Unity xzy :lastpath index:" + lastpath);

        // 最后一个"." 占据整个路径字符串的索引
        int lastdot = FullPath.LastIndexOf(".");
        Debug.Log("Unity xzy :lastdot index:" + lastdot);

        // 纯文件名字长度
        int length = lastdot - lastpath - 1;
        Debug.Log("Unity xzy :recorder file name  length:" + length);

        // 文件目录字符串 xx/xx/xx/
        String beginpart = FullPath.Substring(0, lastpath + 1);
        Debug.Log("Unity xzy :FullPath no has fileName:" + beginpart);

        //  纯文件名字
        String namenoext = FullPath.Substring(lastpath + 1, length);
        Debug.Log("Unity xzy :namenoext  :" + namenoext);

        //   扩展名
        String ext = FullPath.Substring(lastdot);
        Debug.Log("Unity xzy :ext :" + ext);

        // 改名
        String fullnewname = beginpart + "0" + ext;
        File.Move(FullPath, fullnewname);
        Debug.Log("Unity xzy :fullnewname :" + fullnewname);

        return 0;
    }

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值