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
/W - Displays only filenames and directory names (without the added information about each file) in a five-wide display format. dir c:*. This form of the DIR command will also display directories. They can be identified by the DIR label that follows the directory name.
The dir command displays a list of files and subdirectories in a directory. With the /S option, it recurses subdirectories and lists their contents as well.
DIR C:\WINDOWS /w -Displays the contents of the Windows subdirectory on the screen in wide format (up to five filenames per line).
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
Another version with slight differences from the ones above:
for /f %x in ('dir /b /on *.doc') do @echo %~nx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With