VideoHelp Forum

Try DVDFab and download streaming video, copy, convert or make Blu-rays,DVDs! Download free trial !
+ Reply to Thread
Results 1 to 11 of 11
Thread
  1. Hi, please can someone help a poor cat ?


    I'm already in a batch and I have
    Code:
    %~nx1
    that for example contain: MyVideoFile.MP4

    I want to get simply MP4 in another variable, and not .MP4

    How can I do? thanks
    Quote Quote  
  2. 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
    Quote Quote  
  3. 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.
    Quote Quote  
  4. I need to remove the "." from the extension:

    so for example ".AVI" have to be simply "AVI"
    Quote Quote  
  5. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    Batch files can also do string operations (e.g. Len, Substring, Rstring, Trim, etc).

    Scott
    Quote Quote  
  6. 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
    Quote Quote  
  7. Originally Posted by raffriff42 View Post
    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
    oh it works

    thanks
    Quote Quote  
  8. 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 ......
    that /i is there to ignore lower and upper case letter difference
    or
    Code:
    set "look_for_extension=mp4"
    for %%a in ("%~nx1") do set "extension=%%~xa"
    if /i ".%look_for_extension%"=="%extension%" do ......
    Quote Quote  
  9. oh my cat, what I have to dO?

    what's the correct way?
    Quote Quote  
  10. 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?
    Quote Quote  
  11. AHHH ok thanks
    Quote Quote  



Similar Threads