windows - Renaming files in one format to the other -


i have batch of files named in following format

str1_xxxxxxxxxx_str2.txt

i remove xxxxxxxxxx part.

that rename

str1_str2.txt

update:

to make simple, consider str1 random string random length dont know. may include character "_".

str2 string know.

xxxxxxxxxxxx random string fixed length, part want remove.

test.bat

@echo off set file=str1_xxxxxxxxxx_str2.txt set file2=%file:*_=% /f "delims=_" %%a in ("%file%") set file1=%%a set file1=%file1%_%file2:*_=% ren %file% %file1% 

try this. place batch file have text file.

updated

now try this

@echo off setlocal enabledelayedexpansion set file=str1_2_xxxxxxxxxx_str2.txt call :reverse %file% file1 /f "delims=_" %%a in ("%file1%") set file2=%%a set file1=%file1:*_=% set file1=%file1:*_=% call :reverse %file1% file3 call :reverse %file2% file4 set file1=%file3%_%file4% set file1=%file1: =% ren %file% %file1% goto :eof  :reverse set str=%~1 set cnt=0 :loop if "%str%" equ "" (     goto :eof     ) set chr=!str:~0,1! set str=%str:~1% set %2=%chr%!%2!  goto loop 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -