简体   繁体   English

删除文件扩展名批处理或C#

[英]Removing file extensions batch or c#

Is there a way to mass remove file extensions in batch or c# 有没有一种方法可以批量或批量删除c#文件扩展名

I have found ren *.loaded *.torrent very handy but with the files I work with the .loaded come after an .torrent extension, using the ren trick it becomes *.torrent.torrent :P (a bit OCD on file names). 我发现ren * .loaded * .torrent非常方便,但是随着我使用.loaded处理的文件出现在.torrent扩展名之后,使用ren把戏变成* .torrent.torrent:P(文件名有点OCD) 。

So is there a way I can remove the file extension or would it be better to use another extension renaming solution? 因此,有什么方法可以删除文件扩展名,还是最好使用其他扩展名重命名解决方案?

Thanks in advance :) 提前致谢 :)

(I thought c# as it might be great to let the user enter the extensions to change - though I could add this myself later, no idea how to start :P) (我以为是C#,因为最好让用户输入要更改的扩展名-尽管我以后可以自己添加扩展名,但不知道如何开始:P)

You can do it like this 你可以这样

rename *.* *.torrent

to remove extentions 删除扩展

rename *.* *.

Using .Net you can do something like this: 使用.Net您可以执行以下操作:

DirectoryInfo dir = new DirectoryInfo(@"C:\PathName");
foreach (FileInfo fileInfo in dir.GetFiles("*.*"))
{
    File.Move(fileInfo.FullName, fileInfo.FullName.Replace(fileInfo.Extension, string.Empty));
}

You can replace *.* or string.Empty with other extensions. 您可以将*.*string.Empty替换为其他扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM