I need to copy some files with long names from a source directory to a specific destination. But depending on the last 8 characters of the file name (without considering the extension) they must be stored in a different folder.
For example I have files with these names:
20191210,163958414,PA008A021SE002A021,**SP019A021SE002A021**.cfg
20201005,212914881,PA009A021SE002A021,**SP024A021SE002A021**.dat
20201006,212914881,PA009A021SE002A021,**SP024A021SE002A021**.cfg
In this case, the last two files must be saved in the same folder, but it will be different from the folder where the first file must be stored.
I've tried using an if, but maybe robocopy can filter by name easier though I don't know, it's my first time using robocopy.
I've tried this, but it clearly doesn't work. I would greatly appreciate your help in this matter.
@echo off
pushd "C:\origen"
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set "name=%%a"
if %%a:~39,-4 EQU SP019A021SE002A021 (robocopy "%cd%" "C:\destino1\!name:~39,-4!\OSCILOGRAFIAS" "%%a")
)
popd
Yes, it was easier than I imagined. I hope the answer will be useful to someone like me who is not in the field of programming