.NET后端通过本地地址(C:\\Users\\曾彬\\Desktop\\UpdateOld\\bin\\Debug\\2023112420385119805.jpg)取图片名,跟图片名前面所以部分的案例
时间: 2023-11-25 07:52:23 浏览: 22
以下是通过本地地址获取图片名及其前缀的.NET后端代码示例:
```csharp
string filePath = @"C:\Users\曾彬\Desktop\UpdateOld\bin\Debug\2023112420385119805.jpg";
string fileNameWithExtension = Path.GetFileName(filePath); // 获取文件名及扩展名
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); // 获取文件名不包括扩展名
string fileExtension = Path.GetExtension(filePath); // 获取文件扩展名
string directoryName = Path.GetDirectoryName(filePath); // 获取文件所在目录的完整路径
string prefix = filePath.Substring(0, filePath.LastIndexOf(fileNameWithoutExtension)); // 获取文件名前缀
```
相关问题
.NET后端通过本地地址(C:\\Users\\曾彬\\Desktop\\UpdateOld\\bin\\Debug\\2023112420385119805.jpg)取图片名的案例
以下是.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("文件不存在!");
}
}
}
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)