I am trying to loop through a folder of files and rename them based on the last characters of the file. These files do not have extensions. My goal is:
- file ends with TXT eg ItemTXT, move it to the same location and rename as Item.txt
- file does not end with TXT, move it to the same location and rename as Item.xxx
I think I on the right track, but for some reason the if/else returns the else consition every time I test
@echo off
setlocal EnableDelayedExpansion
set pat=C:\Users\king\latest30
echo %pat%
for %%g in (%pat%\*) do (
set fnamelast3="%%~nxg:~-3%"
echo filename: %%~nxg fnamelast3: %fnamelast3%
if "%fnamelast3%" neq "TXT" (
echo %pat%/%%~nxg.fil
) ELSE (
rem does send with TXT
echo %pat%/%fname%.txt
)
)