batch-filedir

How to dir without showing extension (batch)


For example, I have the folder d:\temp\ and four word document files in it (.doc)

I know that

dir /b "d:\temp"

will give me

File1.doc
File2.doc
File3.doc
File4.doc

But how can I do it so that there are only file names without extensions?

like

File1
File2
File3
File4

Solution

  • for %a in ("d:\temp\*") do @echo %~na
    

    or for batch file:

    for %%a in ("d:\temp\*") do @echo %%~na
    

    to display also directories you can use:

    for /f "delims=" %%a in (' dir /f "d:\temp\*"') do @echo %%~na