Search code examples
cmdpathfilenamesfile-extensionsubdirectory

Get filename without path and extension using in cmd prompt


I have a folder with subfolders and files.

I want filenames inside this folder without path and extension.

I don't want any filenames inside the subfolders (no recursivity).


Solution

  • for /f "tokens=*" %i in ('dir /b /a-d') do echo %~ni
    

    to use it in a batchfile, double the percent-signs:

    for /f "tokens=*" %%i in ('dir /b /a-d') do echo %%~ni