On 05.06.2017 22:33, novice wrote:
> Wau, it's magic to me, how this work, but it's work great! Thank you very
> much! I understund basic batch and simple for-loops, but this is so clever.
> Before I try this, I try to understund, how it's work, but I don't
> understand it.. Second last row is something, what is too complicated to me;
> (call set s=%%a:~%n%,10%%_%%a:~,%i%%%%%a:~%j%%%).
"call" just substitutes one level of %. If n=20, i=19 and j=30 then after
the call is executed you get:
set s=%a:~20,10%_%a:~,19%%a:~30%
Type "set /?" for an explanation of this command.
>>If the "-" is only in the date part but not in the name part of the file
>>name, try this:
> I found some files, where player name include "-" character. I can handle
> these cases manually, but I wonder, could batch also handle these cases,
> after some modification?
Then don't search for the first but for last "-" in the file name:
echo off
for /f %%i in ('dir /b *pgn') do call :sub %%i
goto :eof
:sub
set a=%1
set n=-1
:loop
set /a n=n+1
call set s=%%a:~%n%,1%%
if [%s%]==[] goto :end
if [%s%]==[-] set /a m=n
goto :loop
:end
set /a n=m-7
set /a i=n-1
set /a j=n+10
call set s=%%a:~%n%,10%%_%%a:~,%i%%%%%a:~%j%%%
echo ren %a% %s%
> Second problem in my files. Some of files is named like this;
>
> Player1_vs_Player2_2010_05_05.pgn
> Player2_vs_Player1_2011_06_06_2.pgn
> Player2_vs_Player1_2011_06_06_3.pgn
>
> I need a second batch, what rename these files like this;
>
> Player1_vs_Player2_2010-05-05.pgn
> Player2_vs_Player1_2011-06-06_2.pgn
> Player2_vs_Player1_2011-06-06_3.pgn
Separate these files from the others
mkdir a
mkdir b
move *_20??_??_??_* a\
move *_20??_??_??* b\
Then you can also use the above code, but don't search for
the last "-" but for the last "_".