Reputation: 147
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
Upvotes: 10
Views: 24613
Reputation: 476
Another version with slight differences from the ones above:
for /f %x in ('dir /b /on *.doc') do @echo %~nx
Upvotes: 3
Reputation: 834
The following code, when run via a batch file that uses @echo off, should work:
for /f "skip=7 tokens=5 delims=. " %%g in ('dir d:\temp') do echo %%g
Will print all file names without spaces in them. Tested and does so for my F:\ thumb drive.
Edit: for /f "tokens=1 delims=." %%g in ('dir /b d:\temp') do echo %%g
Will print out files and directories in a given path with spaces and is simpler anyway.
Upvotes: 0
Reputation: 57252
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
Upvotes: 19