.NET后端通过本地地址(C:\\Users\\曾彬\\Desktop\\UpdateOld\\bin\\Debug\\2023112420385119805.jpg)取图片名的案例
时间: 2023-11-25 13:52:23 浏览: 40
以下是.NET后端通过本地地址取图片名的代码示例:
```csharp
string path = @"C:\Users\曾彬\Desktop\UpdateOld\bin\Debug\2023112420385119805.jpg";
string fileName = Path.GetFileName(path);
Console.WriteLine(fileName); // 输出:2023112420385119805.jpg
```
其中,`Path.GetFileName()`方法可以获取指定路径的文件名,包括扩展名。
--相关问题--:
1. 如何在.NET中获取文件的扩展名?
2. 如何在.NET中判断指定路径是否存在文件?
3. 如何在.
相关问题
.NET后端通过本地地址(C:\\Users\\曾彬\\Desktop\\UpdateOld\\bin\\Debug\\2023112420385119805.jpg),更改图片名的案例
以下是.NET后端通过本地地址更改图片名的案例:
```csharp
using System;
using System.IO;
namespace RenameImage
{
class Program
{
static void Main(string[] args)
{
string oldPath = @"C:\Users\曾彬\Desktop\UpdateOld\bin\Debug\2023112420385119805.jpg";
string newPath = @"C:\Users\曾彬\Desktop\UpdateOld\bin\Debug\newName.jpg";
// 检查文件是否存在
if (File.Exists(oldPath))
{
// 更改文件名
File.Move(oldPath, newPath);
Console.WriteLine("文件名更改成功!");
}
else
{
Console.WriteLine("文件不存在!");
}
}
}
}
```
.NET后端获取C:\Users\曾彬\Pictures\Saved Pictures\壁纸\14.jpg路径的案例
在.NET后端中获取文件路径可以使用System.IO命名空间中的Path类。具体实现如下:
```csharp
string filePath = Path.Combine(@"C:\Users\曾彬\Pictures\Saved Pictures\壁纸", "14.jpg");
Console.WriteLine(filePath); // 输出:C:\Users\曾彬\Pictures\Saved Pictures\壁纸\14.jpg
```
阅读全文
相关推荐




