Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How To Change A Character In All Documents

DZone's Guide to

How To Change A Character In All Documents

·
Free Resource
how to change a character in all documents



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 block
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}