C#编程实现获取文件夹中所有文件的文件名
作者:Jan.David 时间:2022-11-16 07:53:10
本文实例讲述了C#编程实现获取文件夹中所有文件的文件名。分享给大家供大家参考,具体如下:
想实现这样一个功能:批量修改一个目录所有jpg文件的文件名,在其原始基础上加上特定字符串
我先把一个目录里所有的格式为jpg的文件名存储到数组里,然后统一修改数组值来批量修改jpg文件的文件名
代码如下:
using System;
using System.IO;
namespace ConsoleApplication7
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
string dirp=@"d:\\d";
DirectoryInfo mydir = new DirectoryInfo(dirp);
foreach (FileSystemInfo fsi in mydir.GetFileSystemInfos())
{
if (fsi is FileInfo)
{
FileInfo fi = (FileInfo)fsi;
string x=System.IO.Path.GetDirectoryName(fi.FullName);
Console.WriteLine(x);
string s=System.IO.Path.GetExtension(fi.FullName);
string y=System.IO.Path.GetFileNameWithoutExtension(fi.FullName);
Console.WriteLine(y);
if(s==".jpg")
{
System.IO.File.Copy(fi.FullName,x+@"\oo"+fi.Name); //在原文件名前加上OO
System.IO.File.Delete(fi.FullName);
}
}
}
Console.WriteLine("成功");
Console.ReadLine();
}
}
}
希望本文所述对大家C#程序设计有所帮助。
标签:C#,文件夹,文件名
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android实现GridView中ImageView动态变换的方法
2022-06-21 06:16:55
unity实现虚拟摇杆控制Virtual Joystick
2022-09-26 11:56:28
![](https://img.aspxhome.com/file/2023/3/77263_0s.jpg)
Gradle的安装和环境变量的配置详解
2023-07-11 04:56:37
![](https://img.aspxhome.com/file/2023/2/83552_0s.png)
Android中手机录屏并转换GIF的两种方式
2021-12-03 13:00:52
![](https://img.aspxhome.com/file/2023/9/138029_0s.png)
Java语法中Lambda表达式无法抛出异常的解决
2022-10-13 01:04:43
Android中Splash应用启动白屏问题的解决方法
2022-08-25 14:24:33
Log4j.properties配置及其使用
2023-05-14 21:06:18
本地编译打包项目部署到服务器并且启动方式
2022-02-18 06:27:45
![](https://img.aspxhome.com/file/2023/6/125566_0s.png)
Java常见面试题之多线程和高并发详解
2023-07-24 09:33:51
![](https://img.aspxhome.com/file/2023/4/108174_0s.jpg)
java 8如何自定义收集器(collector)详解
2022-02-12 07:22:17
如何用C#实现SAGA分布式事务
2022-11-29 20:34:49
![](https://img.aspxhome.com/file/2023/2/67552_0s.png)
String类型传递是值传递,char[]类型传递是引用传递的实现
2022-06-01 09:33:44
java异常处理执行顺序详解try catch finally
2022-10-01 04:10:10
![](https://img.aspxhome.com/file/2023/2/62122_0s.png)
MyBatisPlus中CRUD使用方法详解
2023-04-10 18:31:43
Spring-boot的debug调试代码实例
2023-10-17 04:49:01
Android开发中使用sqlite实现新闻收藏和取消收藏的功能
2023-01-27 18:15:13
![](https://img.aspxhome.com/file/2023/1/129011_0s.jpg)
使用Prometheus+Grafana的方法监控Springboot应用教程详解
2023-10-31 13:08:12
![](https://img.aspxhome.com/file/2023/2/72342_0s.jpg)
Android实现手机振动设置的方法
2021-08-02 23:46:21
![](https://img.aspxhome.com/file/2023/3/97853_0s.png)
实现Android studio设置自动导包及自动导包快捷键
2022-03-22 00:05:26
![](https://img.aspxhome.com/file/2023/3/100633_0s.png)
详解spring boot集成RabbitMQ
2022-06-25 17:56:07