重命名文件夹中的一些文件 [英] Rename some files in a folder

查看:284
本文介绍了重命名文件夹中的一些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有改变一些文件的名称(即,动态添加ID到每一个名字),使用C#中的文件夹中。一个任务

I have a task of changing the names of some files (that is, adding id to each name dynamically) in a folder using C#.

例:要的help.txt 1help.txt

Example: help.txt to 1help.txt

我怎样才能做到这一点?

How can I do this?

推荐答案

看一看的 FileInfo的

做这样的事情:

void RenameThem()
{
    DirectoryInfo d = new DirectoryInfo("c:/dir/");
    FileInfo[] infos = d.GetFiles("*.myfiles");
    foreach(FileInfo f in infos)
    {
        // Do the renaming here
        File.Move(f.FullName, Path.Combine(f.DirectoryName, "1" + f.Name));
    }
}

这篇关于重命名文件夹中的一些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆