Find root name of file in DOS

How to get the root name of a file, using dos scripting?
Who is Participating?
knightEknightConnect With a Mentor Commented:
If by root name you mean the part before the .extension:

@echo off
 for %%F in (*.txt) do @echo  %%~nF
I used  *.txt  as a generic filespec, but it can by any filespec or a specific file.
Note that in a batch file, you must double-up the % symbols as I did above.  If you want to run that straight from a command line (no batch) then use single percents:

for %F in (*.txt) do @echo  %~nF
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.