Skip to content

Instantly share code, notes, and snippets.

@DannyDouglass
Created September 1, 2013 02:58
Show Gist options
  • Save DannyDouglass/6402052 to your computer and use it in GitHub Desktop.
Save DannyDouglass/6402052 to your computer and use it in GitHub Desktop.
def replaceFileContents( path, patternToReplace, newProjectName )
fileContents = File.read ( path )
fileContents = fileContents.gsub( patternToReplace, newProjectName )
File.open( path, 'w' ) { | file | file.puts fileContents }
end
def packageInitiator( startDirectory, patternToReplace, newProjectName )
directoryItems = Dir.glob( startDirectory ).reverse
directoryItems.each do | path |
# ignoring ruby scripts so I don't change contents of this file
if( FileTest.file? ( path ) and File.extname( path ) != '.rb' )
replaceFileContents( path, patternToReplace, newProjectName )
end
if( path.include? patternToReplace )
oldPath = File.dirname(path)
newPath = oldPath + '/' + File.basename( path ).gsub( patternToReplace, newProjectName )
File.rename( path, newPath )
end
end
end
packageInitiator( './**/*', '{projectName}', 'MyNewProjectName' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment