WinXP dir command: 3 and 4 char extensions are the same?











up vote
3
down vote

favorite












I'm trying to recursively search a directory tree to find all of the .asp files using the following command:



dir *.asp /s


For some reason, this returns not only the asp files, but also the aspx files.



How can I force it to ignore the aspx files?










share|improve this question




























    up vote
    3
    down vote

    favorite












    I'm trying to recursively search a directory tree to find all of the .asp files using the following command:



    dir *.asp /s


    For some reason, this returns not only the asp files, but also the aspx files.



    How can I force it to ignore the aspx files?










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I'm trying to recursively search a directory tree to find all of the .asp files using the following command:



      dir *.asp /s


      For some reason, this returns not only the asp files, but also the aspx files.



      How can I force it to ignore the aspx files?










      share|improve this question















      I'm trying to recursively search a directory tree to find all of the .asp files using the following command:



      dir *.asp /s


      For some reason, this returns not only the asp files, but also the aspx files.



      How can I force it to ignore the aspx files?







      windows-xp command-line dir






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 29 '17 at 1:48









      phuclv

      8,87063788




      8,87063788










      asked Jan 28 '11 at 12:58









      chris

      4,922176079




      4,922176079






















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          dir /x


          For compatibility reasons, Windows generates a 8.3 name for every long file name created, and wildcard matching code (FindFirstFile()) checks both the original and shortened names. Use dir /x to see what short names are assigned to each file.



          The "extension" part of a 8.3 name is always created by simply truncating the last extension to at most 3 characters: .aspx to .ASP





          When using the NTFS filesystem, 8.3 name creation can be disabled system-wide using:



          fsutil behavior set disable8dot3


          However, this won't affect existing names. You will have to rename each file and then rename it back to its original name.





          See also: Directory search in Windows Command Prompt shows incorrect output!






          share|improve this answer























          • Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files?
            – chris
            Jan 28 '11 at 14:17






          • 1




            @chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp.
            – grawity
            Jan 28 '11 at 14:19












          • according to this answer you can use fsutil 8dot3name strip directory to remove the existing names, no need to rename them
            – phuclv
            Apr 22 '17 at 16:18










          • Why does FindFirstFile find short names?
            – phuclv
            Jun 12 '17 at 2:34


















          up vote
          0
          down vote













          Of course this varies according to what command interpreter's DIR command one uses. The DIR command in Take Command, for example, only matches long names by default and so doesn't exhibit this behaviour. (Matching of short as well as long names can be turned on for compatibility with CMD's DIR command.) So there are ways to address this that don't require FSUTIL and administrator privileges.






          share|improve this answer




























            up vote
            0
            down vote













            Interesting - seems to be a bug...



            Considering, I would pipe it through find like so:



            dir /s *.asp | find /i /v ".aspx "





            share|improve this answer























            • it's not a bug, as per grawity's answer. But why do you leave a space at the end of aspx?
              – phuclv
              Mar 29 '17 at 1:49






            • 1




              @phuclv, the trailing space must be removed, because it becaome part of the search string otherwise; anyway, this approach would also exclude files that have .aspx somewhere in the middle of their names, like file.aspx.name.asp, which should actually be included...
              – aschipfl
              Nov 28 at 13:07


















            up vote
            0
            down vote













            If you have PowerShell, you can use:



            dir *.asp -r | remove-item


            If you don't have PowerShell, why not?






            share|improve this answer




























              up vote
              0
              down vote















              As user grawity anready said in their answer, it is because the wildcards used by cmd's internal commands and several external ones also match against 8.3 file names, which are enabled by default.



              To work around that, there are several ways, some of which I want to show you:





              You can use findstr to filter the file names returned by dir:



              dir /S /B /A:-D "*.asp" | findstr /IEC:".asp"


              This does not even match files that have .asp somewhere in their names (like file.asp.aspx), nor does it exclude files that have .aspx in their names (like file.aspx.asp).



              The switch /B lets dir return a pure list of file names/paths, which can be filtered properly. The option /A:-D excludes any matching directories.





              Alternatively, the where command could be used, which handles wildcards differently than dir:



              where /R "." "*.asp"


              The disadvantage is that this command also regards the content of the PATHEXT variable, so this would also match a file that end in .asp.exe, given that .EXE is contained in PATHEXT; to avoid that, you could temporarily clear the PATHEXT variable (by set "PATHEXT_BACKUP=%PATHEXT%" & set "PATHEXT=") and restore it later (by set "PATHEXT=%PATHEXT_BACKUP%" & set "PATHEXT_BACKUP=").





              This answer by user Konrad shows a way to change the default behaviour of creating 8.3 file names of items with an extension with more than 3 characters, which in turn prevents most of such unintended matches. But unfortunately this does not change any current 8.3 file names. And of course there could theoretically be situations where the 8.3 file names are still matching although quite unlikely.



              I have to admit that I did not yet test this...






              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',
                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%2f238900%2fwinxp-dir-command-3-and-4-char-extensions-are-the-same%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                5
                down vote



                accepted










                dir /x


                For compatibility reasons, Windows generates a 8.3 name for every long file name created, and wildcard matching code (FindFirstFile()) checks both the original and shortened names. Use dir /x to see what short names are assigned to each file.



                The "extension" part of a 8.3 name is always created by simply truncating the last extension to at most 3 characters: .aspx to .ASP





                When using the NTFS filesystem, 8.3 name creation can be disabled system-wide using:



                fsutil behavior set disable8dot3


                However, this won't affect existing names. You will have to rename each file and then rename it back to its original name.





                See also: Directory search in Windows Command Prompt shows incorrect output!






                share|improve this answer























                • Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files?
                  – chris
                  Jan 28 '11 at 14:17






                • 1




                  @chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp.
                  – grawity
                  Jan 28 '11 at 14:19












                • according to this answer you can use fsutil 8dot3name strip directory to remove the existing names, no need to rename them
                  – phuclv
                  Apr 22 '17 at 16:18










                • Why does FindFirstFile find short names?
                  – phuclv
                  Jun 12 '17 at 2:34















                up vote
                5
                down vote



                accepted










                dir /x


                For compatibility reasons, Windows generates a 8.3 name for every long file name created, and wildcard matching code (FindFirstFile()) checks both the original and shortened names. Use dir /x to see what short names are assigned to each file.



                The "extension" part of a 8.3 name is always created by simply truncating the last extension to at most 3 characters: .aspx to .ASP





                When using the NTFS filesystem, 8.3 name creation can be disabled system-wide using:



                fsutil behavior set disable8dot3


                However, this won't affect existing names. You will have to rename each file and then rename it back to its original name.





                See also: Directory search in Windows Command Prompt shows incorrect output!






                share|improve this answer























                • Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files?
                  – chris
                  Jan 28 '11 at 14:17






                • 1




                  @chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp.
                  – grawity
                  Jan 28 '11 at 14:19












                • according to this answer you can use fsutil 8dot3name strip directory to remove the existing names, no need to rename them
                  – phuclv
                  Apr 22 '17 at 16:18










                • Why does FindFirstFile find short names?
                  – phuclv
                  Jun 12 '17 at 2:34













                up vote
                5
                down vote



                accepted







                up vote
                5
                down vote



                accepted






                dir /x


                For compatibility reasons, Windows generates a 8.3 name for every long file name created, and wildcard matching code (FindFirstFile()) checks both the original and shortened names. Use dir /x to see what short names are assigned to each file.



                The "extension" part of a 8.3 name is always created by simply truncating the last extension to at most 3 characters: .aspx to .ASP





                When using the NTFS filesystem, 8.3 name creation can be disabled system-wide using:



                fsutil behavior set disable8dot3


                However, this won't affect existing names. You will have to rename each file and then rename it back to its original name.





                See also: Directory search in Windows Command Prompt shows incorrect output!






                share|improve this answer














                dir /x


                For compatibility reasons, Windows generates a 8.3 name for every long file name created, and wildcard matching code (FindFirstFile()) checks both the original and shortened names. Use dir /x to see what short names are assigned to each file.



                The "extension" part of a 8.3 name is always created by simply truncating the last extension to at most 3 characters: .aspx to .ASP





                When using the NTFS filesystem, 8.3 name creation can be disabled system-wide using:



                fsutil behavior set disable8dot3


                However, this won't affect existing names. You will have to rename each file and then rename it back to its original name.





                See also: Directory search in Windows Command Prompt shows incorrect output!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 20 '17 at 10:16









                Community

                1




                1










                answered Jan 28 '11 at 13:52









                grawity

                230k35484543




                230k35484543












                • Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files?
                  – chris
                  Jan 28 '11 at 14:17






                • 1




                  @chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp.
                  – grawity
                  Jan 28 '11 at 14:19












                • according to this answer you can use fsutil 8dot3name strip directory to remove the existing names, no need to rename them
                  – phuclv
                  Apr 22 '17 at 16:18










                • Why does FindFirstFile find short names?
                  – phuclv
                  Jun 12 '17 at 2:34


















                • Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files?
                  – chris
                  Jan 28 '11 at 14:17






                • 1




                  @chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp.
                  – grawity
                  Jan 28 '11 at 14:19












                • according to this answer you can use fsutil 8dot3name strip directory to remove the existing names, no need to rename them
                  – phuclv
                  Apr 22 '17 at 16:18










                • Why does FindFirstFile find short names?
                  – phuclv
                  Jun 12 '17 at 2:34
















                Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files?
                – chris
                Jan 28 '11 at 14:17




                Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files?
                – chris
                Jan 28 '11 at 14:17




                1




                1




                @chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp.
                – grawity
                Jan 28 '11 at 14:19






                @chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp.
                – grawity
                Jan 28 '11 at 14:19














                according to this answer you can use fsutil 8dot3name strip directory to remove the existing names, no need to rename them
                – phuclv
                Apr 22 '17 at 16:18




                according to this answer you can use fsutil 8dot3name strip directory to remove the existing names, no need to rename them
                – phuclv
                Apr 22 '17 at 16:18












                Why does FindFirstFile find short names?
                – phuclv
                Jun 12 '17 at 2:34




                Why does FindFirstFile find short names?
                – phuclv
                Jun 12 '17 at 2:34












                up vote
                0
                down vote













                Of course this varies according to what command interpreter's DIR command one uses. The DIR command in Take Command, for example, only matches long names by default and so doesn't exhibit this behaviour. (Matching of short as well as long names can be turned on for compatibility with CMD's DIR command.) So there are ways to address this that don't require FSUTIL and administrator privileges.






                share|improve this answer

























                  up vote
                  0
                  down vote













                  Of course this varies according to what command interpreter's DIR command one uses. The DIR command in Take Command, for example, only matches long names by default and so doesn't exhibit this behaviour. (Matching of short as well as long names can be turned on for compatibility with CMD's DIR command.) So there are ways to address this that don't require FSUTIL and administrator privileges.






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Of course this varies according to what command interpreter's DIR command one uses. The DIR command in Take Command, for example, only matches long names by default and so doesn't exhibit this behaviour. (Matching of short as well as long names can be turned on for compatibility with CMD's DIR command.) So there are ways to address this that don't require FSUTIL and administrator privileges.






                    share|improve this answer












                    Of course this varies according to what command interpreter's DIR command one uses. The DIR command in Take Command, for example, only matches long names by default and so doesn't exhibit this behaviour. (Matching of short as well as long names can be turned on for compatibility with CMD's DIR command.) So there are ways to address this that don't require FSUTIL and administrator privileges.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 22 '11 at 17:27









                    JdeBP

                    22.4k14890




                    22.4k14890






















                        up vote
                        0
                        down vote













                        Interesting - seems to be a bug...



                        Considering, I would pipe it through find like so:



                        dir /s *.asp | find /i /v ".aspx "





                        share|improve this answer























                        • it's not a bug, as per grawity's answer. But why do you leave a space at the end of aspx?
                          – phuclv
                          Mar 29 '17 at 1:49






                        • 1




                          @phuclv, the trailing space must be removed, because it becaome part of the search string otherwise; anyway, this approach would also exclude files that have .aspx somewhere in the middle of their names, like file.aspx.name.asp, which should actually be included...
                          – aschipfl
                          Nov 28 at 13:07















                        up vote
                        0
                        down vote













                        Interesting - seems to be a bug...



                        Considering, I would pipe it through find like so:



                        dir /s *.asp | find /i /v ".aspx "





                        share|improve this answer























                        • it's not a bug, as per grawity's answer. But why do you leave a space at the end of aspx?
                          – phuclv
                          Mar 29 '17 at 1:49






                        • 1




                          @phuclv, the trailing space must be removed, because it becaome part of the search string otherwise; anyway, this approach would also exclude files that have .aspx somewhere in the middle of their names, like file.aspx.name.asp, which should actually be included...
                          – aschipfl
                          Nov 28 at 13:07













                        up vote
                        0
                        down vote










                        up vote
                        0
                        down vote









                        Interesting - seems to be a bug...



                        Considering, I would pipe it through find like so:



                        dir /s *.asp | find /i /v ".aspx "





                        share|improve this answer














                        Interesting - seems to be a bug...



                        Considering, I would pipe it through find like so:



                        dir /s *.asp | find /i /v ".aspx "






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jul 18 '12 at 22:25









                        Tom Wijsman

                        50k23164244




                        50k23164244










                        answered Jan 28 '11 at 13:29









                        Multiverse IT

                        4,0781219




                        4,0781219












                        • it's not a bug, as per grawity's answer. But why do you leave a space at the end of aspx?
                          – phuclv
                          Mar 29 '17 at 1:49






                        • 1




                          @phuclv, the trailing space must be removed, because it becaome part of the search string otherwise; anyway, this approach would also exclude files that have .aspx somewhere in the middle of their names, like file.aspx.name.asp, which should actually be included...
                          – aschipfl
                          Nov 28 at 13:07


















                        • it's not a bug, as per grawity's answer. But why do you leave a space at the end of aspx?
                          – phuclv
                          Mar 29 '17 at 1:49






                        • 1




                          @phuclv, the trailing space must be removed, because it becaome part of the search string otherwise; anyway, this approach would also exclude files that have .aspx somewhere in the middle of their names, like file.aspx.name.asp, which should actually be included...
                          – aschipfl
                          Nov 28 at 13:07
















                        it's not a bug, as per grawity's answer. But why do you leave a space at the end of aspx?
                        – phuclv
                        Mar 29 '17 at 1:49




                        it's not a bug, as per grawity's answer. But why do you leave a space at the end of aspx?
                        – phuclv
                        Mar 29 '17 at 1:49




                        1




                        1




                        @phuclv, the trailing space must be removed, because it becaome part of the search string otherwise; anyway, this approach would also exclude files that have .aspx somewhere in the middle of their names, like file.aspx.name.asp, which should actually be included...
                        – aschipfl
                        Nov 28 at 13:07




                        @phuclv, the trailing space must be removed, because it becaome part of the search string otherwise; anyway, this approach would also exclude files that have .aspx somewhere in the middle of their names, like file.aspx.name.asp, which should actually be included...
                        – aschipfl
                        Nov 28 at 13:07










                        up vote
                        0
                        down vote













                        If you have PowerShell, you can use:



                        dir *.asp -r | remove-item


                        If you don't have PowerShell, why not?






                        share|improve this answer

























                          up vote
                          0
                          down vote













                          If you have PowerShell, you can use:



                          dir *.asp -r | remove-item


                          If you don't have PowerShell, why not?






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            If you have PowerShell, you can use:



                            dir *.asp -r | remove-item


                            If you don't have PowerShell, why not?






                            share|improve this answer












                            If you have PowerShell, you can use:



                            dir *.asp -r | remove-item


                            If you don't have PowerShell, why not?







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 25 '13 at 16:00









                            Peter Hahndorf

                            8,51453558




                            8,51453558






















                                up vote
                                0
                                down vote















                                As user grawity anready said in their answer, it is because the wildcards used by cmd's internal commands and several external ones also match against 8.3 file names, which are enabled by default.



                                To work around that, there are several ways, some of which I want to show you:





                                You can use findstr to filter the file names returned by dir:



                                dir /S /B /A:-D "*.asp" | findstr /IEC:".asp"


                                This does not even match files that have .asp somewhere in their names (like file.asp.aspx), nor does it exclude files that have .aspx in their names (like file.aspx.asp).



                                The switch /B lets dir return a pure list of file names/paths, which can be filtered properly. The option /A:-D excludes any matching directories.





                                Alternatively, the where command could be used, which handles wildcards differently than dir:



                                where /R "." "*.asp"


                                The disadvantage is that this command also regards the content of the PATHEXT variable, so this would also match a file that end in .asp.exe, given that .EXE is contained in PATHEXT; to avoid that, you could temporarily clear the PATHEXT variable (by set "PATHEXT_BACKUP=%PATHEXT%" & set "PATHEXT=") and restore it later (by set "PATHEXT=%PATHEXT_BACKUP%" & set "PATHEXT_BACKUP=").





                                This answer by user Konrad shows a way to change the default behaviour of creating 8.3 file names of items with an extension with more than 3 characters, which in turn prevents most of such unintended matches. But unfortunately this does not change any current 8.3 file names. And of course there could theoretically be situations where the 8.3 file names are still matching although quite unlikely.



                                I have to admit that I did not yet test this...






                                share|improve this answer

























                                  up vote
                                  0
                                  down vote















                                  As user grawity anready said in their answer, it is because the wildcards used by cmd's internal commands and several external ones also match against 8.3 file names, which are enabled by default.



                                  To work around that, there are several ways, some of which I want to show you:





                                  You can use findstr to filter the file names returned by dir:



                                  dir /S /B /A:-D "*.asp" | findstr /IEC:".asp"


                                  This does not even match files that have .asp somewhere in their names (like file.asp.aspx), nor does it exclude files that have .aspx in their names (like file.aspx.asp).



                                  The switch /B lets dir return a pure list of file names/paths, which can be filtered properly. The option /A:-D excludes any matching directories.





                                  Alternatively, the where command could be used, which handles wildcards differently than dir:



                                  where /R "." "*.asp"


                                  The disadvantage is that this command also regards the content of the PATHEXT variable, so this would also match a file that end in .asp.exe, given that .EXE is contained in PATHEXT; to avoid that, you could temporarily clear the PATHEXT variable (by set "PATHEXT_BACKUP=%PATHEXT%" & set "PATHEXT=") and restore it later (by set "PATHEXT=%PATHEXT_BACKUP%" & set "PATHEXT_BACKUP=").





                                  This answer by user Konrad shows a way to change the default behaviour of creating 8.3 file names of items with an extension with more than 3 characters, which in turn prevents most of such unintended matches. But unfortunately this does not change any current 8.3 file names. And of course there could theoretically be situations where the 8.3 file names are still matching although quite unlikely.



                                  I have to admit that I did not yet test this...






                                  share|improve this answer























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote











                                    As user grawity anready said in their answer, it is because the wildcards used by cmd's internal commands and several external ones also match against 8.3 file names, which are enabled by default.



                                    To work around that, there are several ways, some of which I want to show you:





                                    You can use findstr to filter the file names returned by dir:



                                    dir /S /B /A:-D "*.asp" | findstr /IEC:".asp"


                                    This does not even match files that have .asp somewhere in their names (like file.asp.aspx), nor does it exclude files that have .aspx in their names (like file.aspx.asp).



                                    The switch /B lets dir return a pure list of file names/paths, which can be filtered properly. The option /A:-D excludes any matching directories.





                                    Alternatively, the where command could be used, which handles wildcards differently than dir:



                                    where /R "." "*.asp"


                                    The disadvantage is that this command also regards the content of the PATHEXT variable, so this would also match a file that end in .asp.exe, given that .EXE is contained in PATHEXT; to avoid that, you could temporarily clear the PATHEXT variable (by set "PATHEXT_BACKUP=%PATHEXT%" & set "PATHEXT=") and restore it later (by set "PATHEXT=%PATHEXT_BACKUP%" & set "PATHEXT_BACKUP=").





                                    This answer by user Konrad shows a way to change the default behaviour of creating 8.3 file names of items with an extension with more than 3 characters, which in turn prevents most of such unintended matches. But unfortunately this does not change any current 8.3 file names. And of course there could theoretically be situations where the 8.3 file names are still matching although quite unlikely.



                                    I have to admit that I did not yet test this...






                                    share|improve this answer














                                    As user grawity anready said in their answer, it is because the wildcards used by cmd's internal commands and several external ones also match against 8.3 file names, which are enabled by default.



                                    To work around that, there are several ways, some of which I want to show you:





                                    You can use findstr to filter the file names returned by dir:



                                    dir /S /B /A:-D "*.asp" | findstr /IEC:".asp"


                                    This does not even match files that have .asp somewhere in their names (like file.asp.aspx), nor does it exclude files that have .aspx in their names (like file.aspx.asp).



                                    The switch /B lets dir return a pure list of file names/paths, which can be filtered properly. The option /A:-D excludes any matching directories.





                                    Alternatively, the where command could be used, which handles wildcards differently than dir:



                                    where /R "." "*.asp"


                                    The disadvantage is that this command also regards the content of the PATHEXT variable, so this would also match a file that end in .asp.exe, given that .EXE is contained in PATHEXT; to avoid that, you could temporarily clear the PATHEXT variable (by set "PATHEXT_BACKUP=%PATHEXT%" & set "PATHEXT=") and restore it later (by set "PATHEXT=%PATHEXT_BACKUP%" & set "PATHEXT_BACKUP=").





                                    This answer by user Konrad shows a way to change the default behaviour of creating 8.3 file names of items with an extension with more than 3 characters, which in turn prevents most of such unintended matches. But unfortunately this does not change any current 8.3 file names. And of course there could theoretically be situations where the 8.3 file names are still matching although quite unlikely.



                                    I have to admit that I did not yet test this...







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 28 at 13:04









                                    aschipfl

                                    216113




                                    216113






























                                        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%2f238900%2fwinxp-dir-command-3-and-4-char-extensions-are-the-same%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

                                        If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                        Alcedinidae

                                        Can an atomic nucleus contain both particles and antiparticles? [duplicate]