Hi All,
I need to rename a file if it exists with a prefix (i.e. "MORE****.txt"). More exactly in my code
@echo on
FOR /F %%i in ('dir %DIRINPUT%MORE*.txt /B') do (
IF %ERRORLEVEL% EQU 0 (
echo file found
set FILENAME=%%i
) else (
echo ERROR: file not found
)
)
I want to avoid the system error "file not found" and display my message "ERROR: file not found" without exit from my batch file.
I tried to use this code
set FILE01=MORE*.txt
IF EXIST %DIRINPUT%%FILE01% (
echo file found
) else (
echo ERROR: file not found
)
but I receive an error if the file doesn' exist.
Any help will be well appreciated.
Thanks in advance for your kind support.
Regards,
Giovanni
How to check file name from prefix
Moderator: DosItHelp
Re: How to check file name from prefix
This will echo the filename only if it exists.
Code: Select all
@echo on
FOR /F %%i in ('dir %DIRINPUT%MORE*.txt /B /a-d 2^>nul ') do echo "%%i"
Re: How to check file name from prefix
Good!! Thank you very much indeed for your suggestion and for the quick reply.