I am trying to come up with a batch file to copy files based on their names.
The filenames are in form aaa_xx-XX-ccc.txt
where aaa
and ccc
do not matter (variable length), but xx
are 2 character codes. I would like to copy the files into their respective xx
folders and these folders would also be created by the script.
Here I found something that almost suit my needs: Batch file to copy files based on characters in filename
@echo off setlocal enableextensions enabledelayedexpansion for %%x in (*.txt) do ( set "filename=%%x" set "folder=!filename:~1,2!" if not exist !folder! mkdir !folder! copy "%%x" !folder! )
But I would like to be looking for the xx
not only by its position in the filename, but by the specific character (underscore) and position in the filename.
Is there any way to do it?
Update - example: I have the following files in a single folder:
My-Project_ar-SA-2016114-12h33m10s.txt
My-Project_cs-CZ-2016114-12h33m8s.text
My-Project_da-DK-2016114-12h33m10s.txt
The "template" for the filenames is "[project-name]_[language-CODE]-[dateAndTime].txt
And I want to copy the first file into a different location\ar folder (for example "C:\Output\ar"), the second file into "C:\Output\cs" etc.