Announcing the new Datavyu v1.3.6 with enhanced features and transcription support!

Hello, I have several files with arguments that I've already coded. I would like to change the name of the arguments without doing it manually (Spreadsheet -> Vocab Editor) and doing so for each file individually. Is there a script that can handle this? Thank you!

asked 24 Jul '13, 15:20

LanaKarasik's gravatar image

LanaKarasik
81111115
accept rate: 0%


Yup there's a script for that. The template below will first search the file to confirm that the argument has the old name and then it changes it.

begin

#These lines define the location of the files that you want change the argument names
filedir = "/Volumes/LABDOCS/StudiesCurrent/ToolsFunkyTools/Coding/EXPORT/"
filenames = Dir.new(filedir).entries

#Begin loop over files
for file in filenames

#Check that the files in the folder are openshapa files
  if file.include?(".opf") and file[0].chr != '.' 
    $db, $pj = load_db(filedir + file)

#Get the variable/column that the argument name that you want to change is in    
    variablename = getVariable("variablename")

        #Begin loop to check that the old   argument name is in the file
    if variablename.arglist.include?("oldargumentname")

    #This actually changes the argument name        
    variablename.change_arg_name("oldargumentname", "newargumentname")
    #This sets the variable so that the new argument name sticks
    setVariable("variablename", variablename)
    #This saves each openshapa file 
    save_db(filedir + file)     
    puts "Saving file."
      end
    end
  end 
end
permanent link

answered 25 Jul '13, 11:40

david's gravatar image

david ♦
143235
accept rate: 4%

edited 25 Jul '13, 11:42

Absolutely. Below is the above script modified to change 2 argument names from two different variables. You can change as many arguments from as many variables as you'd like with one script. Something to keep an eye on is that you have the appropriate number of "end"s.

#These lines define the location of the files that you want change the argument names
  filedir = "/Volumes/LABDOCS/StudiesCurrent/ToolsFunkyTools/Coding/EXPORT/" filenames = Dir.new(filedir).entries

   #Begin loop over files
   for file in filenames
   #Check that the files in the folder are openshapa files 
     if file.include?(".opf") and file[0].chr != '.' $db, $pj = load_db(filedir + file)

   #Get the variable/column that the argument name that you want to change is in 
      variablename = getVariable("variablename") 
      othervariablename = getVariable("othervariablename")

   #Begin loop to check that the old argument name is in the file 
         if variablename.arglist.include?("oldargumentname") 
            if variablename.arglist.include?("olderargumentname")

  #This actually changes the argument name        
    variablename.change_arg_name("oldargumentname", "newargumentname")
    othervariablename.change_arg_name("olderargumentname", "newerargumentname")

    #This sets the variable so that the new argument name sticks
     setVariable("variablename", variablename)
     setVariable("othervariablename", othervariablename)

     #This saves each openshapa file 
      save_db(filedir + file)     
     puts "Saving file."

          end
       end
     end
   end
end
permanent link

answered 26 Jul '13, 14:05

david's gravatar image

david ♦
143235
accept rate: 4%

edited 26 Jul '13, 18:23

Great! I just tried it and it worked. How can I modify the script to change multiple arguments within 1 variable/column and multiple variables with arguments to be changed? Can this be handled in 1 script? Thank you!

permanent link

answered 25 Jul '13, 11:42

LanaKarasik's gravatar image

LanaKarasik
81111115
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×46
×6
×1
×1

question asked: 24 Jul '13, 15:20

question was seen: 3,878 times

last updated: 26 Jul '13, 18:23

powered by OSQA