на пробу:
Код:
@echo off
SETLOCAL EnableDelayedExpansion
set $DIR=C:\TEST
chcp 1251>nul
for /r "%$DIR%" %%a in (*.txt) do (
for /f "delims=," %%b in ('findstr/bc:"CN=" /c:"O=" "%%a"') do set $%%b
set $CN=!$CN:"=!
set $O=!$O:"=!
ren "%%a" "!$CN!_!$O!%%~xa">nul 2>&1||(chcp 866>nul
echo/&echo/File name "!$CN!_!$O!%%~xa" is busy^^!&echo/File "%%a" skipped.
chcp 1251>nul))