Hi, please can someone help a poor cat?
I'm already in a batch and I havethat for example contain: MyVideoFile.MP4Code:%~nx1
I want to get simply MP4 in another variable, and not .MP4
How can I do? thanks
+ Reply to Thread
Results 1 to 11 of 11
-
-
n = file name without extension
x = file extension
nx = file name with extension
So you probably simply want %~n1 (you can do e.g. "%~n1.mkv" to use the same file name with mkv extension).
https://stackoverflow.com/a/15568171 -
Or embedded help -
Code:for /?
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive. -
I need to remove the "." from the extension:
so for example ".AVI" have to be simply "AVI" -
Batch files can also do string operations (e.g. Len, Substring, Rstring, Trim, etc).
Scott -
I'm curious myself, so...
https://www.google.com/search?q=batch+substring
https://stackoverflow.com/questions/636381/what-is-the-best-way-to-do-a-substring-in-a-batch-file
Code:@echo dot+ext = %~x1 set dot_ext=%~x1 set ext=%dot_ext:~1,99% @echo extension = %ext%
Code:dot+ext = .jpg extension = jpg
-
That's not a good thing. Batch manipulates extension with that dot at the beginning. You get back soon how to add back that dot there.
If you compare extensions, simply add one dot there:
Code:for %%a in ("%~nx1") do set "extension=%%~xa" if /i ".mp4"=="%extension%" do ......
or
Code:set "look_for_extension=mp4" for %%a in ("%~nx1") do set "extension=%%~xa" if /i ".%look_for_extension%"=="%extension%" do ......
-
Whatever works , it is correct,
just wanted to show you that you can create "if" condition with that dot added so you do not have to remove it. Otherwise why to remove it?
Similar Threads
-
Batch MKV title to filename renaming.
By Zareaus in forum Newbie / General discussionsReplies: 7Last Post: 16th May 2018, 04:12 -
batch that compare filename in 2 folder
By marcorocchini in forum Newbie / General discussionsReplies: 2Last Post: 3rd Oct 2017, 04:58 -
Find correct file extension and removing Metatags (Batch)
By anon2 in forum EditingReplies: 3Last Post: 19th Sep 2017, 12:43 -
MP4Tools specify output filename?
By themelz in forum MacReplies: 1Last Post: 27th Apr 2016, 06:56 -
batch method of joining MP4s based on filename
By edd1234 in forum EditingReplies: 3Last Post: 30th Oct 2013, 18:39