Created
September 1, 2013 02:58
-
-
Save DannyDouglass/6402052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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