cheesyone
cheesyone

Reputation: 31

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)

Upvotes: 2

Views: 802

Answers (2)

Chris Snowden
Chris Snowden

Reputation: 5002

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.

Upvotes: 0

Tony Borf
Tony Borf

Reputation: 4660

You can do it like this

rename *.* *.torrent

to remove extentions

rename *.* *.

Upvotes: 1

Related Questions