SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ruby find/replace script

    Hi all,

    I newbie in ruby and need create ruby script that find by all my images, such as:

    Code:
    <img src="images/image.gif" />
    and transform to:

    Code:
    <img src="/layout/site/images/image.gif" />
    but it only some images(that are in another folder)...

    here the code I already make, I need suggestion how read file and replace <img> tag:

    Code:
    require 'fileutils'
    
    
    def changeIMGEntry(imageFile)
    		
    	Dir["Z:/dir_jsp_for_change/*.jsp"].each do |fileJsp|
    		
    		puts fileJsp
    		
    		File.open(fileJsp).each do |line|
    		
    			puts line	
    			
    		end
    				
    		
    	end
    
    end
    
    Dir["dir_image_for_change/*.gif"].each do |file|	
    	
    	changeIMGEntry(file)
    	
    end

    someone have any idea ?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is much easier to accomplish with sed. Search for "sed documentation".


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •