The detail requirement is I need to move files from source folder to Destination folder based on the File names. For example
ABC_TEST1.txt
should be moved to Y:\Dest\ABC
, EFG_TEST1.txt
should be moved to Y:\Dest\EFG
, XYZ.txt
should be moved to Y:\Dest\Unkonow
, GHI_TEST1.txt
should be moved to Y:\Dest\Unkown
.
I tried the script below.
setlocal EnableDelayedExpansion
for %%F in (*.txt) do (
set FileName=%%F
echo %%F
if x%FileName:_=%==x%FileName%(
for /F "tokens=1* delims=_" %%B in ("%%~nXF") do (
ren "%%F" "%%C"
if exist "Y:\Dest\%%B" (move "%%C" "Y:\Dest\%%B") else (move "%%C" "Y:\Dest\Unknown")
)
)else (move "%%C" "Y:\Dest\Unknown")
)
endlocal
If I add the if condition the script is not working, without the if condition it's working.
ABC_TEST1.txt
should be moved to Y:\Dest\ABC
, EFG_TEST1.txt
should be moved to Y:\Dest\EFG
It's not moving the XYZ.txt
, GHI_TEST1.txt
to Y:\Dest\Unkonow
.