是否有任何功能在.NET中更改文件扩展名?或者我必须重命名文件?谢谢
例如,我想将扩展名为".resxx"的目录中的每个文件重命名为.resx.我的代码有什么问题?
Dim [option] As SearchOption = SearchOption.AllDirectories [option] = SearchOption.AllDirectories
Dim fileNames As String() = Directory.GetFiles("C:\New Folder", "*.resxx", [option])
For Each f In fileNames
Dim t As New FileInfo(f.ToString)
MsgBox(Mid(f, 1, f.Length - 4))
t.MoveTo(Mid(f, 1, f.Length - 4) + ".resx")
Next
Run Code Online (Sandbox Code Playgroud)
小智 5
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myFiles As String()
myFiles = IO.Directory.GetFiles("D:\Temp\", "*.txt")
Dim newFilePath As String
For Each filepath As String In myFiles
newFilePath = filepath.Replace(".txt", ".html")
System.IO.File.Move(filepath, newFilePath)
Next
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)