You can use a FOR /F loop and set the
"USEBACKQ TOKENS=2 DELIMS=_ " like that to parse out and get the date string from the file name to reuse in subsequent commands accordingly for the operations you need.
You will then use a mixture of commands such as
DEL to perform the file operations to get those moved over to the new date string folder.
Note: Be sure to set the
Src= variable value to be the folder where these files exist, and be sure to set the
Dest= variable value to be the folder where the files will be moved and the
yyyy-mm-dd folder will be created for those files to reside once moved.
FOR /F "USEBACKQ TOKENS=2 DELIMS=_ " %%A IN (`DIR /B "%Src%\*.txt"`) DO (
IF NOT EXIST "%%~A" MD "%%~A"
XCOPY /F /Y "%Src%\*%%~A*.txt" "%Dest%\%%~A\" && DEL /Q /F "%Src%\*%%~A*.txt"
- FOR /F
delims=xxx - specifies a delimiter set. This replaces the
default delimiter set of space and tab.
tokens=x,y,m-n - specifies which tokens from each line are to
be passed to the for body for each iteration.
This will cause additional variable names to
be allocated. The m-n form is a range,
specifying the mth through the nth tokens. If
the last character in the tokens= string is an
asterisk, then an additional variable is
allocated and receives the remaining text on
the line after the last token parsed.
usebackq - specifies that the new semantics are in force,
where a back quoted string is executed as a
command and a single quoted string is a
literal string command and allows the use of
double quotes to quote file names in