Trying to create a file to override another one....

Hi, i am trying to create a new file with same name of another to override id but i get error…

 function unlockLevel(precLvl)
 
     local path = system.pathForFile( “Save/Save.txt”);
  local hFile = io.open(path, “r”) --Reading.
  local overFile = io.open(path, “w”) --Writing Overwrite.
  --local wFile, errrHnd = io.open(path, “w”);
  

  
  local getNext = false;
  local getLasts = false;
  local countF = 0;
  local lines = {};
  local newLine = “”;
  local restOfFile;
  --local lineCt = 1;
  for line in hFile:lines() do
  print(“XOXOXOOXOXXO”)
   if(getNext) then
      for w in string.gmatch(line, “%S+”) do
       countF = countF + 1;
       if(countF == 4)then
        newLine = newLine…“1”;
       else
        newLine = newLine…w…" ";
       end
       
            
      end
      print("NUOVA LINEA ORA: "…newLine);
      lines[#lines + 1] = newLine;
      getNext = false;
      
   
   else
      if(line == precLvl) then
       lines[#lines + 1] = line;
       getNext = true;
         
      else
       lines[#lines + 1] = line;
      end
   end
   
   
  end
 
  hFile:close();
  path = nil;
  --hFile=nil;
  
              for i=1,#lines do
               print("xxxxxx> "…lines[i] )
              end
  
  
  overFile:write( “XOXOOXOXOX”)
  --io.close( overFile )
  
  overFile = nil
  
  --local results, reason = os.remove( system.pathForFile( “Save.txt”, path  ) );
  --local file = io.open( path, “w” )
  --file:write( lines )
  --io.close( file )
  --file = nil
   

 

 end

Do you mean you’re trying overwrite an existing file?

If so, you may be prevented from overwriting it if the file is open already.

Please take a look at my io extension library to see if it helps:

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/io.lua

Mmmm i don’t know. Of course, file was closed…i wil reinstall corona to check if the problem can be solved so…

Do you mean you’re trying overwrite an existing file?

If so, you may be prevented from overwriting it if the file is open already.

Please take a look at my io extension library to see if it helps:

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/io.lua

Mmmm i don’t know. Of course, file was closed…i wil reinstall corona to check if the problem can be solved so…