考虑:
strPath= c:\images\gallery\add.gif
我需要将此文件从 add.gif
重命名为 thumb1.gid
,并且我应该编写一个命令方法,无论文件名如何。我们要
用下面的名称替换该名称。
string strfilename = **"thumb"**
****结果thum.gif**
strPath= c:\images\gallery\thum.gif
**
最佳答案
您有几个问题,在 XML 文件中查找值并重命名文件。
要查找与 Gallery2 或其他内容相对应的数字,我建议您查看 Stack Overflow question How to implement a simple XPath lookup 解释了如何在 XML 文件中查找节点/值。
要在 .NET 中重命名文件,请使用以下内容:
using System.IO;
FileInfo fi = new FileInfo("c:\\images\\gallery\\add.gif");
if (fi.Exists)
{
fi.MoveTo("c:\\images\\gallery\\thumb3.gif");
}
当然,您可以使用字符串变量而不是字符串文字作为路径。
这应该为您提供足够的信息来拼凑并解决您特定的查找重命名问题。
关于asp.net - 如何在 C# 中重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1673924/