Dir.chdir("D:\\change_characters") #changes the current working directory
getFiles=`dir /B *.TXT` #passes this command to the shell
fileList=getFiles.split(/\n/) #creates an Array separated with \n
fileList.length.times{ #opening of a block
fileName=fileList.pop #pops the first item out of the Array
#############################
fileA=File.open(fileName,"r") #opens the file thats in fileName as read only
doc=fileA.read #reads the file into the doc string
fileA.close #closes the file
#############################
doc.gsub!(/a/,"@") #replaces "a" with "@" in the doc string
#############################
fileB=File.open(fileName,"w") #deletes and opens a the file in fileName
fileB.write(doc) #writes the contents of doc into the file
fileB.close #closes the file
#############################
} #closing blockRead more: http://feeds.dzone.com/~r/dzone/snippets/~3/BfYCHPIJ0DI/12891