更改多个文件的文件扩展名 [英] Change File Extension on Multiple Files

查看:41
本文介绍了更改多个文件的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件夹中有一些文件.

I have some file in a folder.

D:\Text\Text.FL
D:\Text\Text1.FL
D:\Text\Text2.FL

D:\Text\Text.FL
D:\Text\Text1.FL
D:\Text\Text2.FL

我想将扩展名.FL"重命名为.txt"
我试过这个代码

i want to rename extension ".FL" to ".txt"
I've tried with this code

My.Computer.FileSystem.RenameFile("D:\Text\Text.fl","Text.txt")

但我想缩短那个代码

推荐答案

您想缩短一行代码吗?如果您导入 System.IO 命名空间,您可以调用 File.Move 但在这种情况下您需要传递两个完整路径.也许你真正的意思是你不想为每个文件写出这样的一行.如果您想将文件夹中的所有.fl"文件更改为.txt",那么这就是我要做的:

You want to shorten one line of code? You can call File.Move if you import the System.IO namespace but you would need to pass two full paths in that case. Maybe what you actually mean is that you don't want to have to write out a line like that for each file. If you want to change all ".fl" files to ".txt" in a folder then this is what I would do:

For Each filePath In Directory.GetFiles(folderPath, "*.fl")
    File.Move(filePath, Path.ChangeExtension(filePath, ".txt"))
Next

这篇关于更改多个文件的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆