主题:求助C#修改文件扩展名的问题
我是菜鸟,请高手们帮我看下~
程序生成和结果显示都没问题,但就是没效果,文件夹里的文件名并未改变
想问下问题究竟出在哪里?应该如何修改?
谢谢啦~!
using System;
using System.IO;
public class PathSnippets
{
public static void ChangeExtension()
{
string goodFileName = @"D:\1.txt";
string badFileName = @"D:\";
string result;
result = Path.ChangeExtension(goodFileName, ".old");
Console.WriteLine("ChangeExtension({0}, '.old') returns '{1}'",
goodFileName, result);
result = Path.ChangeExtension(goodFileName, "");
Console.WriteLine("ChangeExtension({0}, '') returns '{1}'",
goodFileName, result);
result = Path.ChangeExtension(badFileName, ".old");
Console.WriteLine("ChangeExtension({0}, '.old') returns '{1}'",
badFileName, result);
}
public static void Main()
{
ChangeExtension();
}
}
程序生成和结果显示都没问题,但就是没效果,文件夹里的文件名并未改变
想问下问题究竟出在哪里?应该如何修改?
谢谢啦~!
using System;
using System.IO;
public class PathSnippets
{
public static void ChangeExtension()
{
string goodFileName = @"D:\1.txt";
string badFileName = @"D:\";
string result;
result = Path.ChangeExtension(goodFileName, ".old");
Console.WriteLine("ChangeExtension({0}, '.old') returns '{1}'",
goodFileName, result);
result = Path.ChangeExtension(goodFileName, "");
Console.WriteLine("ChangeExtension({0}, '') returns '{1}'",
goodFileName, result);
result = Path.ChangeExtension(badFileName, ".old");
Console.WriteLine("ChangeExtension({0}, '.old') returns '{1}'",
badFileName, result);
}
public static void Main()
{
ChangeExtension();
}
}