i have several thousand files similar, different formats, ie:
[block 1] thisfile.txt [block 1] thisfile1.txt [block 1] thisfile2.txt [backup001] thatfile1.doc [backup001] thatfile2.doc [backup001] thatfile3.doc [explode] thisplace.xls [explode] thisplace1.xls [explode] thisplace2.xls i want remove "[text] " , keep else same. since text varies can't strict number of characters ie
set var=%1 @echo %var:~-7% i tried dabble powershell commandline , tried:
dir *.xls | rename-item -newname {$_.name -replace '[explode\s\'} but given following error:
rename-item : input script block parameter 'newname' failed. invalid regular expression pattern: [explode\s\. @ line:1 char:33 + dir *.xls | rename-item -newname <<<< {$_.name -replace '[explode]\s\'} + categoryinfo : invalidargument: (c:\1\[explode... thisfile1.xls:psobject) [rename-item], parameterbindingexception + fullyqualifiederrorid : scriptblockargumentinvocationfailed,microsoft.powershell.commands.renameitemcommand i've searched stackexchange, , 'batch-rename' tag, , found (and tried) several similar things thought tweak, no luck.
here's latest based on stachexchange answer:
for %%f in (*.xls) ( set string=%%f set modified=!string:explode=1! echo !modified! ) i trying replace work... no luck.
using pure batch:
@echo off /f "delims=" %%f in ( 'dir /b /a-d [*]*' ) /f "tokens=1* delims=]" %%a in ( "%%f" ) /f "tokens=*" %%c in ("%%b") ren "%%f" "%%c" using jren.bat regular expression renaming utility, pure script utility (hybrid jscript/batch) runs natively on windows machine xp onward:
call jren "^\[.*?] *" "" /fm "[*]*" you can drop call if use command directly command line.
Comments
Post a Comment