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
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
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).
I'm curious myself, so...
@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:
for %%a in ("%~nx1") do set "extension=%%~xa" if /i ".mp4"=="%extension%" do ......
set "look_for_extension=mp4" for %%a in ("%~nx1") do set "extension=%%~xa" if /i ".%look_for_extension%"=="%extension%" do ......
oh my cat, what I have to dO?
what's the correct way?
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?
AHHH ok thanks