The following code works if there is only one hyphen in your file name. It uses a nested FOR command to split the base file name by the hyphen.
@echo off
for %%F in (*.doc ) do (
echo full name: %%F
echo name without suffix: %%~nF
for /F "tokens=2 delims=-" %%G IN ("%%~nF") DO (
IF /I "%%G"=="important" (echo File is important) else Echo File is not important
)
)
This second set of code checks if the base file name ends in the string you are looking for by using the FINDSTR command. Conditional execution is then used to determine which echo command is executed. The double ampersand is used to execute if the previous command was successful. The double pipe is used to execute if the previous command was not successful.
for %%F in (*.doc ) do (
set "flag="
echo full name: %%F
echo name without suffix: %%~nF
echo %%~nF|findstr /E /I "important" >nul 2>&1 &&echo File is Important || echo file is not important
)
forfilesfeature is what you need.for %%f in ("*-important*.doc") do ...to find and process only document files containing the string-importantin file name?FORcommand.FOR %%f in (*-important.doc *-classified.doc *-sensitive.doc) do ......