You are not logged in.

#1 16 Aug 2020 16:16

PiotrMP006
Member
Registered: 02 Apr 2019
Posts: 12

How do I get an extension if the filename has two dots?

How do I get an extension if the filename has two dots?

ex.

Test.aaa.txt

%~r1  -> aaa.txt

Please help me

Offline

#2 16 Aug 2020 21:15

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: How do I get an extension if the filename has two dots?

Why would .aaa.txt be the extension instead of just .txt? What if you had A.File.Name.Like.This.2020.HEVC.x265.mkv?

Also, %~r doesn't work because %~r isn't a valid variable substitution command. %~x gets the extension.

Offline

#3 18 Aug 2020 08:59

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: How do I get an extension if the filename has two dots?

You'll have to process the file name as a parameter twice to do what you want.  In the simplest case (where you want only two "extensions"), you could do this:

set primary_ext="%~1"

for %%A in ("%~n1") do set secondary_ext="%%~xA"

set combined_ext="%secondary_ext%%primary_ext%"

I believe this should be "safe" for use where there is only one extension (or none at all).

If you wanted further extension depth, it should be fairly straight forward to adapt this into a loop mechanism.

Last edited by bluesxman (18 Aug 2020 09:00)


cmd | *sh | ruby | chef

Offline

Board footer

Powered by