简体   繁体   中英

Removing file extensions batch or c#

Is there a way to mass remove file extensions in batch or 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).

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)

You can do it like this

rename *.* *.torrent

to remove extentions

rename *.* *.

Using .Net you can do something like this:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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