Windows batch script has to accept an input file with a specific extension





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-2















How to make a .bat file accept a file which ends in a particular extension from the path of the .bat file? I am new to batch commands.



Eg:
I have to run the following command in bat:

some command inputfile.extension.



File with the extension has to be taken from the path of bat file and this command has to be executed.



Thanks in advance!










share|improve this question























  • It depends on what the current directory is when the .bat file is invoked. Please provide more information, including that actual command and input file you're wanting to use. Do not provide an answer to this comment as another comment, use the edit facility instead, remembering to format the code using the {} button.

    – Compo
    Jan 3 at 7:25








  • 1





    %0 represents the batch files drive path name and extension, with the ~ modifier you can select just drive and path %~dp0. See call /?

    – LotPings
    Jan 3 at 9:39













  • Please consider accepting my answer.

    – double-beep
    Feb 11 at 18:49


















-2















How to make a .bat file accept a file which ends in a particular extension from the path of the .bat file? I am new to batch commands.



Eg:
I have to run the following command in bat:

some command inputfile.extension.



File with the extension has to be taken from the path of bat file and this command has to be executed.



Thanks in advance!










share|improve this question























  • It depends on what the current directory is when the .bat file is invoked. Please provide more information, including that actual command and input file you're wanting to use. Do not provide an answer to this comment as another comment, use the edit facility instead, remembering to format the code using the {} button.

    – Compo
    Jan 3 at 7:25








  • 1





    %0 represents the batch files drive path name and extension, with the ~ modifier you can select just drive and path %~dp0. See call /?

    – LotPings
    Jan 3 at 9:39













  • Please consider accepting my answer.

    – double-beep
    Feb 11 at 18:49














-2












-2








-2


1






How to make a .bat file accept a file which ends in a particular extension from the path of the .bat file? I am new to batch commands.



Eg:
I have to run the following command in bat:

some command inputfile.extension.



File with the extension has to be taken from the path of bat file and this command has to be executed.



Thanks in advance!










share|improve this question














How to make a .bat file accept a file which ends in a particular extension from the path of the .bat file? I am new to batch commands.



Eg:
I have to run the following command in bat:

some command inputfile.extension.



File with the extension has to be taken from the path of bat file and this command has to be executed.



Thanks in advance!







batch-file






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 6:50









Aparna venugopalAparna venugopal

1




1













  • It depends on what the current directory is when the .bat file is invoked. Please provide more information, including that actual command and input file you're wanting to use. Do not provide an answer to this comment as another comment, use the edit facility instead, remembering to format the code using the {} button.

    – Compo
    Jan 3 at 7:25








  • 1





    %0 represents the batch files drive path name and extension, with the ~ modifier you can select just drive and path %~dp0. See call /?

    – LotPings
    Jan 3 at 9:39













  • Please consider accepting my answer.

    – double-beep
    Feb 11 at 18:49



















  • It depends on what the current directory is when the .bat file is invoked. Please provide more information, including that actual command and input file you're wanting to use. Do not provide an answer to this comment as another comment, use the edit facility instead, remembering to format the code using the {} button.

    – Compo
    Jan 3 at 7:25








  • 1





    %0 represents the batch files drive path name and extension, with the ~ modifier you can select just drive and path %~dp0. See call /?

    – LotPings
    Jan 3 at 9:39













  • Please consider accepting my answer.

    – double-beep
    Feb 11 at 18:49

















It depends on what the current directory is when the .bat file is invoked. Please provide more information, including that actual command and input file you're wanting to use. Do not provide an answer to this comment as another comment, use the edit facility instead, remembering to format the code using the {} button.

– Compo
Jan 3 at 7:25







It depends on what the current directory is when the .bat file is invoked. Please provide more information, including that actual command and input file you're wanting to use. Do not provide an answer to this comment as another comment, use the edit facility instead, remembering to format the code using the {} button.

– Compo
Jan 3 at 7:25






1




1





%0 represents the batch files drive path name and extension, with the ~ modifier you can select just drive and path %~dp0. See call /?

– LotPings
Jan 3 at 9:39







%0 represents the batch files drive path name and extension, with the ~ modifier you can select just drive and path %~dp0. See call /?

– LotPings
Jan 3 at 9:39















Please consider accepting my answer.

– double-beep
Feb 11 at 18:49





Please consider accepting my answer.

– double-beep
Feb 11 at 18:49












1 Answer
1






active

oldest

votes


















0
















This can be done using the "0" argument sent to a batch file (%0) which is actually like %~dpnx0, or even simplified %~f0. What you need is the drive letter and the path only. So, you can try:



command %~dp0file.ext


or even much more complicated (might won't work if command.ext is neither in PATH nor in %~dp0):



pushd %cd%
cd %~dp0
command file.ext
popd



%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file
%~$PATH:1 - searches the directories listed in the PATH

environment variable and expands %1 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:



%~dp1 - expands %1 to a drive letter and path only
%~nx1 - expands %1 to a file name and extension only
%~dp$PATH:1 - searches the directories listed in the PATH

environment variable for %1 and expands to the

drive letter and path of the first one found.
%~ftza1 - expands %1 to a DIR like output line




From call /?






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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%2fstackoverflow.com%2fquestions%2f54017563%2fwindows-batch-script-has-to-accept-an-input-file-with-a-specific-extension%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    This can be done using the "0" argument sent to a batch file (%0) which is actually like %~dpnx0, or even simplified %~f0. What you need is the drive letter and the path only. So, you can try:



    command %~dp0file.ext


    or even much more complicated (might won't work if command.ext is neither in PATH nor in %~dp0):



    pushd %cd%
    cd %~dp0
    command file.ext
    popd



    %~1 - expands %1 removing any surrounding quotes (")
    %~f1 - expands %1 to a fully qualified path name
    %~d1 - expands %1 to a drive letter only
    %~p1 - expands %1 to a path only
    %~n1 - expands %1 to a file name only
    %~x1 - expands %1 to a file extension only
    %~s1 - expanded path contains short names only
    %~a1 - expands %1 to file attributes
    %~t1 - expands %1 to date/time of file
    %~z1 - expands %1 to size of file
    %~$PATH:1 - searches the directories listed in the PATH

    environment variable and expands %1 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:



    %~dp1 - expands %1 to a drive letter and path only
    %~nx1 - expands %1 to a file name and extension only
    %~dp$PATH:1 - searches the directories listed in the PATH

    environment variable for %1 and expands to the

    drive letter and path of the first one found.
    %~ftza1 - expands %1 to a DIR like output line




    From call /?






    share|improve this answer




























      0
















      This can be done using the "0" argument sent to a batch file (%0) which is actually like %~dpnx0, or even simplified %~f0. What you need is the drive letter and the path only. So, you can try:



      command %~dp0file.ext


      or even much more complicated (might won't work if command.ext is neither in PATH nor in %~dp0):



      pushd %cd%
      cd %~dp0
      command file.ext
      popd



      %~1 - expands %1 removing any surrounding quotes (")
      %~f1 - expands %1 to a fully qualified path name
      %~d1 - expands %1 to a drive letter only
      %~p1 - expands %1 to a path only
      %~n1 - expands %1 to a file name only
      %~x1 - expands %1 to a file extension only
      %~s1 - expanded path contains short names only
      %~a1 - expands %1 to file attributes
      %~t1 - expands %1 to date/time of file
      %~z1 - expands %1 to size of file
      %~$PATH:1 - searches the directories listed in the PATH

      environment variable and expands %1 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:



      %~dp1 - expands %1 to a drive letter and path only
      %~nx1 - expands %1 to a file name and extension only
      %~dp$PATH:1 - searches the directories listed in the PATH

      environment variable for %1 and expands to the

      drive letter and path of the first one found.
      %~ftza1 - expands %1 to a DIR like output line




      From call /?






      share|improve this answer


























        0












        0








        0









        This can be done using the "0" argument sent to a batch file (%0) which is actually like %~dpnx0, or even simplified %~f0. What you need is the drive letter and the path only. So, you can try:



        command %~dp0file.ext


        or even much more complicated (might won't work if command.ext is neither in PATH nor in %~dp0):



        pushd %cd%
        cd %~dp0
        command file.ext
        popd



        %~1 - expands %1 removing any surrounding quotes (")
        %~f1 - expands %1 to a fully qualified path name
        %~d1 - expands %1 to a drive letter only
        %~p1 - expands %1 to a path only
        %~n1 - expands %1 to a file name only
        %~x1 - expands %1 to a file extension only
        %~s1 - expanded path contains short names only
        %~a1 - expands %1 to file attributes
        %~t1 - expands %1 to date/time of file
        %~z1 - expands %1 to size of file
        %~$PATH:1 - searches the directories listed in the PATH

        environment variable and expands %1 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:



        %~dp1 - expands %1 to a drive letter and path only
        %~nx1 - expands %1 to a file name and extension only
        %~dp$PATH:1 - searches the directories listed in the PATH

        environment variable for %1 and expands to the

        drive letter and path of the first one found.
        %~ftza1 - expands %1 to a DIR like output line




        From call /?






        share|improve this answer















        This can be done using the "0" argument sent to a batch file (%0) which is actually like %~dpnx0, or even simplified %~f0. What you need is the drive letter and the path only. So, you can try:



        command %~dp0file.ext


        or even much more complicated (might won't work if command.ext is neither in PATH nor in %~dp0):



        pushd %cd%
        cd %~dp0
        command file.ext
        popd



        %~1 - expands %1 removing any surrounding quotes (")
        %~f1 - expands %1 to a fully qualified path name
        %~d1 - expands %1 to a drive letter only
        %~p1 - expands %1 to a path only
        %~n1 - expands %1 to a file name only
        %~x1 - expands %1 to a file extension only
        %~s1 - expanded path contains short names only
        %~a1 - expands %1 to file attributes
        %~t1 - expands %1 to date/time of file
        %~z1 - expands %1 to size of file
        %~$PATH:1 - searches the directories listed in the PATH

        environment variable and expands %1 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:



        %~dp1 - expands %1 to a drive letter and path only
        %~nx1 - expands %1 to a file name and extension only
        %~dp$PATH:1 - searches the directories listed in the PATH

        environment variable for %1 and expands to the

        drive letter and path of the first one found.
        %~ftza1 - expands %1 to a DIR like output line




        From call /?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 10:05









        double-beepdouble-beep

        3,10641432




        3,10641432
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f54017563%2fwindows-batch-script-has-to-accept-an-input-file-with-a-specific-extension%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

            MongoDB - Not Authorized To Execute Command

            Npm cannot find a required file even through it is in the searched directory

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith