在 C# 表单中重命名文件夹 [英] Rename folders in c# Form

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

问题描述

我尝试在 C# 中制作一个 Form 程序来重命名很多文件夹.客户必须选择文件夹(以及要重命名的名称),其中包含所有文件夹,例如在 c:\folders\ 中是此文件夹:

i try to make a Form program in c# to rename a lot of folders. The Customers has to choose the folder (and the name to rename), where all the folders are include, for example in c:\folders\ are this folders:

1991 - title1
1992 - title2
1993 - title3
1994 - title4

现在我要把年份改成一个名字,就像这样:

And now i will change the year into a name, like this:

name - title1
name - title2
name - title3
name - title4

示例图片:

我希望你能理解我想要的 :-) 并且你能帮我解决这个问题.

I hope you unterstand what i want :-) and you can help me with this.

问候,马蒂亚斯

推荐答案

一些提示:

  1. 获取所有文件(递归,如果你想要)与

  1. Get all files (recursively if you want) with

Directory.GetFiles(@"c:\folder\")

Directory.GetFiles(@"c:\folder\")

重命名所有文件

File.Move(@"C:\folder\oldname",@"C:\文件夹\新名称");

File.Move(@"C:\folder\oldname", @"C:\folder\newname");

如果您的文件格式是这样,您可以简单地将文件名拆分为-" &用你的名字替换第一部分.

If your file format is like that you can simply split the filename at "-" & replace the first part with your name.

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

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