Category Image Smalltalk for quick and easy "script" work 


 

A need to rename a lot of files came up on a UNix box for me recently. The trick was that a part of the file name had to be modified for easily over a hundred files. I didn't have any interest in trying this manually and I don't have much technical strength with Unix scripts.

Smalltalk to the rescue.

I FTPd the files over to my Mac and fired up Squeak. In 5 minutes I had a workspace that looked something like this (changed a lot from the one I actually used):
 
"Rename files found in a directory." 
dirName := 'path to your directory go here'. 
fileNamePrefix := 'foo'. 
dir := FileDirectory on: dirName. 
fileNames := dir fileNamesMatching: fileNamePrefix, '*'. 
fileNames do: [:orgName | 
newName := orgName copyFrom: 1 to: (orgName size - 6). "strip off the last 6 bytes" 
dir rename: orgName toBe: newName].

FTP the files back over to the Unix box and we're done. 

Posted: Saturday - August 27, 2005 at 12:33 PM           |


©