BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »

Friday, May 21, 2010

Substitute names "left" for "right"

A quick script to replace something in an object name with something else, or simply just remove something by leaving it blank.

global proc doNameReplace() {
string $s[] = `ls -sl`;
string $r = `textField -q -text rField`;
string $w = `textField -q -text wField`;
for ($c in $s) {
string $new = substituteAllString($c,$r,$w);
string $split[];
tokenize $new "|" $split;
rename $c $split[size($split) - 1];
deleteUI replaceNameWin;
}
}
if (`window -ex replaceNameWin`) deleteUI replaceNameWin;
string $win = `window -mnb 0 -mxb 0 -t "Name Replace" replaceNameWin`;
columnLayout;
rowColumnLayout -nc 4 -cw 1 50 -cw 2 75 -cw 3 50 -cw 4 75 -cs 1 10;

text -l "Replace:";
textField rField;
text -l " with ";
textField wField;
setParent..;
rowColumnLayout -nc 2 -cw 1 125 -cw 2 125 -cs 1 10;
button -l "Apply" -c "doNameReplace";
button -l "Cancel" -c "deleteUI $win";
showWindow $win;
window -e -w 275 -h 75 $win;

0 comments: