Subj : Re: Howto copy set of files with rename to shorter name? To : Jonathan de Boyne Pollard From : Steve Date : Sat Mar 09 2002 09:14 am From: "E. S. (Steve) Fabian" Jonathan de Boyne Pollard wrote: > > AB> I have a lot of files with name pattern: LONGNAME_XX-YY.ext, where > AB> XX and YY are changing numbers and LONGNAME is string which is same > AB> for all files. I need to copy them and change their names to > AB> _shorter_ name while preserving the numbers: FOO-XX-YY.ext. > > Using 4NT () : > > for %f in ( longname-[0-9][0-9]-[0-9][0-9].txt ) rename %f F00-%@instr[9,5,%f].txt > In 4NT, 4DOS, and TakeCommand, even cleaner is: for %f in ( longname-[0-9][0-9]-[0-9][0-9].txt ) rename %f F00-%@instr[0,-5,%@name[%f]].txt where @INSTR selects the LAST 5 characters of the NAME portion of the file specification, regardless of the size of "longname". You could also strip the underscore and hyphen from the name to make it shorter: for %f in ( longname_[0-9][0-9]-[0-9][0-9].txt ) ( rename %f F00%@replace[-,,%@instr[0,-5,%@name[%f]]].txt ) Note that the parentheses act as a command continuation marker. -- E. S. "Steve" Fabian ESFabian@BellAtlantic.net POB 1540, Cherry Hill, NJ 08034 Telephone: 856-354-1752 EMPIRE Consultants, Inc. Director, Software Development ------------------------------------------------------------------- --- BBBS/NT v4.01 Flag-2 * Origin: Mach2 Systems (1:342/3) .