I know that "dir /w" or "dir /b" shows only the file name. While "dir /x" or "dir /X" shows the 8.3 format, but together shows all other information like long format file names, dates and size.

is it possible to call dir, that only shows the file names (not showing dates or sizes), and showing that in 8.3 format?

for /R %A in (*.*) do @echo %~nsA %~nA

without subdirectory:

for %A in (*.*) do @echo %~nsA %~nA

add hidden files:

for /F "tokens=*" %A in ('dir /B/A:-/S *') do @echo %~nsA %~nA

without subdirectory:

for /F "tokens=*" %A in ('dir /B/A:- *') do @echo %~nsA %~nA
| improve this answer | |
  • can you include output that proves it does that – barlop Feb 8 '16 at 16:06
  • How would I get it to kick the results of that first command into a text file? I get the following error: "The requested operation cannot be performed on a file with a user-mapped section open." – bdb484 Jul 31 '19 at 2:59

If you just want the 8.3 names and nothing else to be displayed, if you use "dir /-n" you will get the 8.3 name at the beginning of each line. Note: it separates the extension from the filename with a space rather than a period.

C:\Users\User>dir /-n
 Volume in drive C has no label.
 Volume Serial Number is 5C60-1B61

 Directory of C:\Users\User

.             <DIR>             01/28/2015  11:26 PM
..            <DIR>             01/28/2015  11:26 PM
Contacts      <DIR>             12/27/2014  04:46 PM
Desktop       <DIR>             01/25/2015  05:06 PM
DOCUME~1      <DIR>             01/27/2015  10:20 PM
DOWNLO~1      <DIR>             01/27/2015  10:10 PM
FAVORI~1      <DIR>             12/27/2014  04:46 PM
GOOGLE~1      <DIR>             01/28/2015  02:08 AM
Links         <DIR>             01/25/2015  05:06 PM
Music         <DIR>             12/27/2014  04:46 PM
Pictures      <DIR>             12/27/2014  04:46 PM
SAVEDG~1      <DIR>             12/27/2014  04:46 PM
Searches      <DIR>             12/27/2014  04:46 PM
TESTIN~1 TXT                  8 01/28/2015  10:32 PM
TESTIN~2 BAT                175 01/28/2015  11:26 PM
TESTIN~1 BAT                164 01/28/2015  11:26 PM
UNIGIN~1      <DIR>             10/28/2014  07:01 PM
Videos        <DIR>             12/27/2014  04:46 PM
               3 File(s)            347 bytes
              16 Dir(s)  3,896,034,717,696 bytes free

But you can use the "dir /-n" within a for loop in a batch file then extract a substring of the first 12 characters to get rid of the rest of each line. E.g.:

@echo off
setlocal EnableDelayedExpansion

for /f "skip=7 tokens=*" %%i in ('dir /-n ^| find /v "File(s)" ^| find /v "Dir(s)"') do (
   set x=%%i
   echo !x:~0,12!

The "skip=7" skips the first 7 lines, which aren't file nor directory names and the output of the "dir /-n" is piped through two find commands to remove the last two lines produced by "dir /-n" (the pipe symbol "|" needs to be "escaped" by a "^". Since the substring extraction occurs in a for loop in the batch file, "setlocal EnableDelayedExpansion" is needed and "!" needs to be used with the variable x rather than "%". For the above example, you would then see the following output from executing the batch file:

| improve this answer | |
  • Nitpick: one or more spaces. Try creating a file named abc.txt to see this in action. Then, for the fun of it, create a file named abc.docx. – user Jan 29 '15 at 9:47
for %i in (*) do echo %~nsxi


for /f "tokens=4" %i in ('dir /a-d /x "%cd%" ^| find "/"') do echo %i


for /f "tokens=1,2" %i in ('dir /a-d /-n "%cd%" ^| find "/"') do echo %i.%j

or to include directories/folders:

for /f "tokens=4" %i in ('dir /x "%cd%" ^| find "/"') do echo %i

Tested in Win 10

| improve this answer | |

After playing with this for an hour I came up with the following:

from dos prompt:

for /F "tokens=*" %A in ('dir /B/A:-/S c:\Windows') do (@echo %~sA>> "%temp%\file_list_8dot3.txt")

from .BAT or .CMD file:

for /F "tokens=*" %%A in ('dir /B/A:-/S c:\Windows') do (@echo %%~sA>> "%temp%\file_list_8dot3.txt")

note: this script still has problem with long file names, but it will continue and make a 8dot3 text file that can then be pumped into any other batch file.

The following is my whole test .Bat file:

@echo off

set ll=%temp%\file_list_8dot3.txt

if exist "%ll%" del "%ll%"
for /F "tokens=*" %%A in ('dir /B/A:-/S %temp%') do (@echo %%~sA>> "%ll%")

start /wait notepad "%ll%"

if exist "%ll%" del "%ll%"
| improve this answer | |

To list files into all sub directories try this one out:

for /d /r %i in (*.*) do dir "%i" /B > %i/test.txt


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.