Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dir without showing extension (batch)

Tags:

batch-file

dir

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
like image 729
z1lent Avatar asked Jan 26 '15 19:01

z1lent


People also ask

How do I show only file names in a directory?

/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.

What does dir s do in CMD?

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.

What is the option to use with dir so that the information will be displayed in wide format?

DIR C:\WINDOWS /w -Displays the contents of the Windows subdirectory on the screen in wide format (up to five filenames per line).


2 Answers

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
like image 66
npocmaka Avatar answered Sep 19 '22 21:09

npocmaka


Another version with slight differences from the ones above:

for /f %x in ('dir /b /on *.doc') do @echo %~nx
like image 25
Jonathan Roberts Avatar answered Sep 17 '22 21:09

Jonathan Roberts