The code below, there are comments, should be able to read.
functiongetFile (file_name)Localf =assert(Io.open(file_name,'R')) LocalString = F:read ("*all") F:close ()returnstringEndfunctionWriteFile (file_name,string)Localf =assert(Io.open(file_name,'W') ) F:write (String) f:close ()End--get parameters from the command line, traverse the specified directory if there are parameters, no parameters to traverse the current directoryifarg[1] ~=Nil Thencmd="ls".. arg[1]Elsecmd="ls"EndPrint("cmd", cmd)--Io.popen Returns a file, just like the Popen in C.Locals =Io.popen(CMD)LocalFilelists = S:read ("*all")Print(filelists) while true Do --gets the file name from a row in the list of files_,end_pos, line =String.find(Filelists,"([^\n\r]+.txt)", Start_pos)if notEnd_pos Then Break End--print ("wld", line) Localstr =GetFile (line)--put the end of each line at 1, replace with 0, LocalNew =string.gsub(STR,"1,\n","0,\n"); --the replaced string is written to the file. The previous content will be emptiedWriteFile (line, new) Start_pos= End_pos +1End