How to get filename only without path in windows command line?












22














for /r %f in (*) do echo %f


Gives the output filename along with the entire path



pathtodir<filename>


How do i get just the <filename> without the path included? I need to use that 'filename' string.



Also, is it possible to do the following, once the filename is acquired?



for /r %%f in (*) do (
echo "blah blah blah 'filename'" >> blahblah_filename.txt
)









share|improve this question


















  • 2




    For future reference, Microsoft has an online Windows XP - Command-line reference A-Z which is still mostly applicable to later versions. The documentation in the answer you accepted is at the end of the section on the for command.
    – martineau
    Oct 18 '12 at 3:31












  • @martineau: Unfortunately, the online 'Windows XP - Command-line reference A-Z' page is no longer on-line (removed by microsoft) and an alternative for this documentation is not yet available (as far as I can find any codumentation on '%~' argument documentation)
    – PapaAtHome
    Jul 2 '18 at 9:08












  • @PapaAtHome: Fortunately one can still view the command line reference via web.archive.org's wayback machine.
    – martineau
    Jul 2 '18 at 12:36
















22














for /r %f in (*) do echo %f


Gives the output filename along with the entire path



pathtodir<filename>


How do i get just the <filename> without the path included? I need to use that 'filename' string.



Also, is it possible to do the following, once the filename is acquired?



for /r %%f in (*) do (
echo "blah blah blah 'filename'" >> blahblah_filename.txt
)









share|improve this question


















  • 2




    For future reference, Microsoft has an online Windows XP - Command-line reference A-Z which is still mostly applicable to later versions. The documentation in the answer you accepted is at the end of the section on the for command.
    – martineau
    Oct 18 '12 at 3:31












  • @martineau: Unfortunately, the online 'Windows XP - Command-line reference A-Z' page is no longer on-line (removed by microsoft) and an alternative for this documentation is not yet available (as far as I can find any codumentation on '%~' argument documentation)
    – PapaAtHome
    Jul 2 '18 at 9:08












  • @PapaAtHome: Fortunately one can still view the command line reference via web.archive.org's wayback machine.
    – martineau
    Jul 2 '18 at 12:36














22












22








22


17





for /r %f in (*) do echo %f


Gives the output filename along with the entire path



pathtodir<filename>


How do i get just the <filename> without the path included? I need to use that 'filename' string.



Also, is it possible to do the following, once the filename is acquired?



for /r %%f in (*) do (
echo "blah blah blah 'filename'" >> blahblah_filename.txt
)









share|improve this question













for /r %f in (*) do echo %f


Gives the output filename along with the entire path



pathtodir<filename>


How do i get just the <filename> without the path included? I need to use that 'filename' string.



Also, is it possible to do the following, once the filename is acquired?



for /r %%f in (*) do (
echo "blah blah blah 'filename'" >> blahblah_filename.txt
)






windows command-line script batch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 18 '12 at 2:44









Jay

56341123




56341123








  • 2




    For future reference, Microsoft has an online Windows XP - Command-line reference A-Z which is still mostly applicable to later versions. The documentation in the answer you accepted is at the end of the section on the for command.
    – martineau
    Oct 18 '12 at 3:31












  • @martineau: Unfortunately, the online 'Windows XP - Command-line reference A-Z' page is no longer on-line (removed by microsoft) and an alternative for this documentation is not yet available (as far as I can find any codumentation on '%~' argument documentation)
    – PapaAtHome
    Jul 2 '18 at 9:08












  • @PapaAtHome: Fortunately one can still view the command line reference via web.archive.org's wayback machine.
    – martineau
    Jul 2 '18 at 12:36














  • 2




    For future reference, Microsoft has an online Windows XP - Command-line reference A-Z which is still mostly applicable to later versions. The documentation in the answer you accepted is at the end of the section on the for command.
    – martineau
    Oct 18 '12 at 3:31












  • @martineau: Unfortunately, the online 'Windows XP - Command-line reference A-Z' page is no longer on-line (removed by microsoft) and an alternative for this documentation is not yet available (as far as I can find any codumentation on '%~' argument documentation)
    – PapaAtHome
    Jul 2 '18 at 9:08












  • @PapaAtHome: Fortunately one can still view the command line reference via web.archive.org's wayback machine.
    – martineau
    Jul 2 '18 at 12:36








2




2




For future reference, Microsoft has an online Windows XP - Command-line reference A-Z which is still mostly applicable to later versions. The documentation in the answer you accepted is at the end of the section on the for command.
– martineau
Oct 18 '12 at 3:31






For future reference, Microsoft has an online Windows XP - Command-line reference A-Z which is still mostly applicable to later versions. The documentation in the answer you accepted is at the end of the section on the for command.
– martineau
Oct 18 '12 at 3:31














@martineau: Unfortunately, the online 'Windows XP - Command-line reference A-Z' page is no longer on-line (removed by microsoft) and an alternative for this documentation is not yet available (as far as I can find any codumentation on '%~' argument documentation)
– PapaAtHome
Jul 2 '18 at 9:08






@martineau: Unfortunately, the online 'Windows XP - Command-line reference A-Z' page is no longer on-line (removed by microsoft) and an alternative for this documentation is not yet available (as far as I can find any codumentation on '%~' argument documentation)
– PapaAtHome
Jul 2 '18 at 9:08














@PapaAtHome: Fortunately one can still view the command line reference via web.archive.org's wayback machine.
– martineau
Jul 2 '18 at 12:36




@PapaAtHome: Fortunately one can still view the command line reference via web.archive.org's wayback machine.
– martineau
Jul 2 '18 at 12:36










2 Answers
2






active

oldest

votes


















37














Use %~nxf for <filename>.<extension>.



And yes, you can do:



for /r %%f in (*) do (
echo "blah blah blah '%%~nxf'" >> blahblah_%%~nxf.txt
)


See 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.





share|improve this answer





















  • Great answer. Any idea how I could search for a substring in a full path? For example, I want to know if c:codemyapp.gitsomefolder includes the text ".git".
    – Dale Barnard
    Nov 3 '16 at 20:46






  • 1




    You can perform a textual or regex search by piping the path into the find or findstr command, e.g. echo %%f | find ".git" > NUL or echo %%f | findstr /R /C:"\.git\" /C:"\.git>" > NUL and then checking the errorlevel with the if command. (findstr regex is very limited, so that's my attempt at enforcing a leading and [either a trailing or end of string]). Do note that if errorlevel has quirks with fall-through, and you probably can't if %errorlevel% within a loop so you might need to SetLocal EnableDelayedExpansion first and then if !errorlevel! instead.
    – Bob
    Nov 3 '16 at 23:24










  • @DaleBarnard Also, consider using PowerShell - much much less pain and probably more consistent results.
    – Bob
    Nov 3 '16 at 23:24










  • The blah blah is confusing me, what is it supposed to represent? How does the full path of the file and the extracted file name fit into this answer?
    – thebunnyrules
    Apr 28 '17 at 16:38












  • @thebunnyrules %~nxf is the filename, as I said in the first sentence. When you use it within a batch file, you need to double up the %, making it %%~nxf. The blah blah blah is just taking the example in the question and replacing the filename bit with the %%~nxf substitution - the blahs are just filler and have no particular meaning.
    – Bob
    Apr 28 '17 at 16:51



















0














I'm not yet able to comment, but I believe the following should be noted to avoid confusion.



While f can be used as a FOR variable name, it's best to use another letter to avoid confusing it with format letter f (which, as stated in Bob's answer, returns full path name), or at least use a capital F.






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f489240%2fhow-to-get-filename-only-without-path-in-windows-command-line%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    37














    Use %~nxf for <filename>.<extension>.



    And yes, you can do:



    for /r %%f in (*) do (
    echo "blah blah blah '%%~nxf'" >> blahblah_%%~nxf.txt
    )


    See 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.





    share|improve this answer





















    • Great answer. Any idea how I could search for a substring in a full path? For example, I want to know if c:codemyapp.gitsomefolder includes the text ".git".
      – Dale Barnard
      Nov 3 '16 at 20:46






    • 1




      You can perform a textual or regex search by piping the path into the find or findstr command, e.g. echo %%f | find ".git" > NUL or echo %%f | findstr /R /C:"\.git\" /C:"\.git>" > NUL and then checking the errorlevel with the if command. (findstr regex is very limited, so that's my attempt at enforcing a leading and [either a trailing or end of string]). Do note that if errorlevel has quirks with fall-through, and you probably can't if %errorlevel% within a loop so you might need to SetLocal EnableDelayedExpansion first and then if !errorlevel! instead.
      – Bob
      Nov 3 '16 at 23:24










    • @DaleBarnard Also, consider using PowerShell - much much less pain and probably more consistent results.
      – Bob
      Nov 3 '16 at 23:24










    • The blah blah is confusing me, what is it supposed to represent? How does the full path of the file and the extracted file name fit into this answer?
      – thebunnyrules
      Apr 28 '17 at 16:38












    • @thebunnyrules %~nxf is the filename, as I said in the first sentence. When you use it within a batch file, you need to double up the %, making it %%~nxf. The blah blah blah is just taking the example in the question and replacing the filename bit with the %%~nxf substitution - the blahs are just filler and have no particular meaning.
      – Bob
      Apr 28 '17 at 16:51
















    37














    Use %~nxf for <filename>.<extension>.



    And yes, you can do:



    for /r %%f in (*) do (
    echo "blah blah blah '%%~nxf'" >> blahblah_%%~nxf.txt
    )


    See 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.





    share|improve this answer





















    • Great answer. Any idea how I could search for a substring in a full path? For example, I want to know if c:codemyapp.gitsomefolder includes the text ".git".
      – Dale Barnard
      Nov 3 '16 at 20:46






    • 1




      You can perform a textual or regex search by piping the path into the find or findstr command, e.g. echo %%f | find ".git" > NUL or echo %%f | findstr /R /C:"\.git\" /C:"\.git>" > NUL and then checking the errorlevel with the if command. (findstr regex is very limited, so that's my attempt at enforcing a leading and [either a trailing or end of string]). Do note that if errorlevel has quirks with fall-through, and you probably can't if %errorlevel% within a loop so you might need to SetLocal EnableDelayedExpansion first and then if !errorlevel! instead.
      – Bob
      Nov 3 '16 at 23:24










    • @DaleBarnard Also, consider using PowerShell - much much less pain and probably more consistent results.
      – Bob
      Nov 3 '16 at 23:24










    • The blah blah is confusing me, what is it supposed to represent? How does the full path of the file and the extracted file name fit into this answer?
      – thebunnyrules
      Apr 28 '17 at 16:38












    • @thebunnyrules %~nxf is the filename, as I said in the first sentence. When you use it within a batch file, you need to double up the %, making it %%~nxf. The blah blah blah is just taking the example in the question and replacing the filename bit with the %%~nxf substitution - the blahs are just filler and have no particular meaning.
      – Bob
      Apr 28 '17 at 16:51














    37












    37








    37






    Use %~nxf for <filename>.<extension>.



    And yes, you can do:



    for /r %%f in (*) do (
    echo "blah blah blah '%%~nxf'" >> blahblah_%%~nxf.txt
    )


    See 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.





    share|improve this answer












    Use %~nxf for <filename>.<extension>.



    And yes, you can do:



    for /r %%f in (*) do (
    echo "blah blah blah '%%~nxf'" >> blahblah_%%~nxf.txt
    )


    See 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.






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 18 '12 at 3:00









    Bob

    45.4k20137172




    45.4k20137172












    • Great answer. Any idea how I could search for a substring in a full path? For example, I want to know if c:codemyapp.gitsomefolder includes the text ".git".
      – Dale Barnard
      Nov 3 '16 at 20:46






    • 1




      You can perform a textual or regex search by piping the path into the find or findstr command, e.g. echo %%f | find ".git" > NUL or echo %%f | findstr /R /C:"\.git\" /C:"\.git>" > NUL and then checking the errorlevel with the if command. (findstr regex is very limited, so that's my attempt at enforcing a leading and [either a trailing or end of string]). Do note that if errorlevel has quirks with fall-through, and you probably can't if %errorlevel% within a loop so you might need to SetLocal EnableDelayedExpansion first and then if !errorlevel! instead.
      – Bob
      Nov 3 '16 at 23:24










    • @DaleBarnard Also, consider using PowerShell - much much less pain and probably more consistent results.
      – Bob
      Nov 3 '16 at 23:24










    • The blah blah is confusing me, what is it supposed to represent? How does the full path of the file and the extracted file name fit into this answer?
      – thebunnyrules
      Apr 28 '17 at 16:38












    • @thebunnyrules %~nxf is the filename, as I said in the first sentence. When you use it within a batch file, you need to double up the %, making it %%~nxf. The blah blah blah is just taking the example in the question and replacing the filename bit with the %%~nxf substitution - the blahs are just filler and have no particular meaning.
      – Bob
      Apr 28 '17 at 16:51


















    • Great answer. Any idea how I could search for a substring in a full path? For example, I want to know if c:codemyapp.gitsomefolder includes the text ".git".
      – Dale Barnard
      Nov 3 '16 at 20:46






    • 1




      You can perform a textual or regex search by piping the path into the find or findstr command, e.g. echo %%f | find ".git" > NUL or echo %%f | findstr /R /C:"\.git\" /C:"\.git>" > NUL and then checking the errorlevel with the if command. (findstr regex is very limited, so that's my attempt at enforcing a leading and [either a trailing or end of string]). Do note that if errorlevel has quirks with fall-through, and you probably can't if %errorlevel% within a loop so you might need to SetLocal EnableDelayedExpansion first and then if !errorlevel! instead.
      – Bob
      Nov 3 '16 at 23:24










    • @DaleBarnard Also, consider using PowerShell - much much less pain and probably more consistent results.
      – Bob
      Nov 3 '16 at 23:24










    • The blah blah is confusing me, what is it supposed to represent? How does the full path of the file and the extracted file name fit into this answer?
      – thebunnyrules
      Apr 28 '17 at 16:38












    • @thebunnyrules %~nxf is the filename, as I said in the first sentence. When you use it within a batch file, you need to double up the %, making it %%~nxf. The blah blah blah is just taking the example in the question and replacing the filename bit with the %%~nxf substitution - the blahs are just filler and have no particular meaning.
      – Bob
      Apr 28 '17 at 16:51
















    Great answer. Any idea how I could search for a substring in a full path? For example, I want to know if c:codemyapp.gitsomefolder includes the text ".git".
    – Dale Barnard
    Nov 3 '16 at 20:46




    Great answer. Any idea how I could search for a substring in a full path? For example, I want to know if c:codemyapp.gitsomefolder includes the text ".git".
    – Dale Barnard
    Nov 3 '16 at 20:46




    1




    1




    You can perform a textual or regex search by piping the path into the find or findstr command, e.g. echo %%f | find ".git" > NUL or echo %%f | findstr /R /C:"\.git\" /C:"\.git>" > NUL and then checking the errorlevel with the if command. (findstr regex is very limited, so that's my attempt at enforcing a leading and [either a trailing or end of string]). Do note that if errorlevel has quirks with fall-through, and you probably can't if %errorlevel% within a loop so you might need to SetLocal EnableDelayedExpansion first and then if !errorlevel! instead.
    – Bob
    Nov 3 '16 at 23:24




    You can perform a textual or regex search by piping the path into the find or findstr command, e.g. echo %%f | find ".git" > NUL or echo %%f | findstr /R /C:"\.git\" /C:"\.git>" > NUL and then checking the errorlevel with the if command. (findstr regex is very limited, so that's my attempt at enforcing a leading and [either a trailing or end of string]). Do note that if errorlevel has quirks with fall-through, and you probably can't if %errorlevel% within a loop so you might need to SetLocal EnableDelayedExpansion first and then if !errorlevel! instead.
    – Bob
    Nov 3 '16 at 23:24












    @DaleBarnard Also, consider using PowerShell - much much less pain and probably more consistent results.
    – Bob
    Nov 3 '16 at 23:24




    @DaleBarnard Also, consider using PowerShell - much much less pain and probably more consistent results.
    – Bob
    Nov 3 '16 at 23:24












    The blah blah is confusing me, what is it supposed to represent? How does the full path of the file and the extracted file name fit into this answer?
    – thebunnyrules
    Apr 28 '17 at 16:38






    The blah blah is confusing me, what is it supposed to represent? How does the full path of the file and the extracted file name fit into this answer?
    – thebunnyrules
    Apr 28 '17 at 16:38














    @thebunnyrules %~nxf is the filename, as I said in the first sentence. When you use it within a batch file, you need to double up the %, making it %%~nxf. The blah blah blah is just taking the example in the question and replacing the filename bit with the %%~nxf substitution - the blahs are just filler and have no particular meaning.
    – Bob
    Apr 28 '17 at 16:51




    @thebunnyrules %~nxf is the filename, as I said in the first sentence. When you use it within a batch file, you need to double up the %, making it %%~nxf. The blah blah blah is just taking the example in the question and replacing the filename bit with the %%~nxf substitution - the blahs are just filler and have no particular meaning.
    – Bob
    Apr 28 '17 at 16:51













    0














    I'm not yet able to comment, but I believe the following should be noted to avoid confusion.



    While f can be used as a FOR variable name, it's best to use another letter to avoid confusing it with format letter f (which, as stated in Bob's answer, returns full path name), or at least use a capital F.






    share|improve this answer


























      0














      I'm not yet able to comment, but I believe the following should be noted to avoid confusion.



      While f can be used as a FOR variable name, it's best to use another letter to avoid confusing it with format letter f (which, as stated in Bob's answer, returns full path name), or at least use a capital F.






      share|improve this answer
























        0












        0








        0






        I'm not yet able to comment, but I believe the following should be noted to avoid confusion.



        While f can be used as a FOR variable name, it's best to use another letter to avoid confusing it with format letter f (which, as stated in Bob's answer, returns full path name), or at least use a capital F.






        share|improve this answer












        I'm not yet able to comment, but I believe the following should be noted to avoid confusion.



        While f can be used as a FOR variable name, it's best to use another letter to avoid confusing it with format letter f (which, as stated in Bob's answer, returns full path name), or at least use a capital F.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 10 '18 at 8:26









        HYBRID BEING

        2116




        2116






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f489240%2fhow-to-get-filename-only-without-path-in-windows-command-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Plaza Victoria

            In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

            How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...