mfp吧 关注:779贴子:4,997

对所有.mfps文件,文首,文尾批量加相同的文字

只看楼主收藏回复

variable path="/storage/emulated/0/AnMath/scripts/TXT"
list_files(path)
//sleep(6000)
for variable k=0 to size(ans)[0]-1
if(strsub(ans[k],strlen(ans[k])-5,strlen(ans[k]))==".mfps")
list_files(ans[k])
endif
next
//sleep(6000)
for variable k=0 to size(ans)[0]-1
variable fo=fopen("/storage/emulated/0/AnMath/scripts/TXT/"+ans[k],"r","utf_8")
variable fo1=fopen("/storage/emulated/0/AnMath/scripts/TXT*/"+ans[k],"w","utf_8")
fprintf(fo1,"%s\n\n","citingspace::{myfunc}")
do
variable st=freadline(fo)
fprintf(fo1,"%s\n",st)
until(feof(fo))
fprintf(fo1,"\n%s","endcs")
fclose(fo1)
fclose(fo)
next
return


来自Android客户端1楼2016-08-16 18:43回复
    哪里错了


    来自Android客户端4楼2016-08-16 21:11
    收起回复
      2025-12-24 10:10:18
      广告
      不感兴趣
      开通SVIP免广告
      为什么分开执行时可以呢?


      来自Android客户端5楼2016-08-16 21:18
      收起回复
        function f_xj(s)//新建文件
        return create_file(s)
        endf
        function f_qk(s)//清空文字内容
        variablefe = fopen(s, "w","UTF-8")
        fprintf(fe,"%s","")
        fclose(fe)
        endf
        function f_storage_f(s,str)
        variable fp=fopen(s,"a","UTF-8")
        fprintf(fp,"%s\n",str)
        fclose(fp)
        endf


        来自Android客户端9楼2016-08-17 06:08
        回复
          help
          @language:simplified_chinese
          //例variable path="/storage/emulated/0/AnMath/scripts/TXT" ⇒原.mfps所在<文件夹>路径
          //例variable new_path="/storage/emulated/0/AnMath/scripts/TXT_new" ⇒新.mfps所在<文件夹>路径
          //例variable csname="myf"
          //添加空间名如"myf"或"myf::f"
          @end
          endh
          function f_mfps_aedit(path,new_path,csname)
          if(ls("temp")==1)
          f_qk("temp")
          else
          f_xj("temp")
          endif
          variable list=list_files(path)
          for variable k=0 to size(list)[0]-1
          if(strsub(list[k],strlen(list[k])-5,strlen(list[k]))==".mfps")
          f_storage_f("temp",list[k])
          endif
          next
          variable fp=fopen("temp","r","utf_8")
          do
          variable str=freadline(fp)
          variable fo=fopen(path+"/"+str,"r","utf_8")
          variable fo1=fopen(new_path+"/"+str,"w","utf_8")
          //fprintf(fo1,"%s\n\n","citingspace ::func")
          fprintf(fo1,"%s\n\n","citingspace ::"+csname)
          do
          variable st=freadline(fo)
          fprintf(fo1,"%s\n",st)
          until(feof(fo))
          fprintf(fo1,"\n%s","endcs")
          fclose(fo1)
          fclose(fo)
          until(feof(fp))
          fclose(fp)
          //f_gm(new_path,path)
          endf


          来自Android客户端12楼2016-08-17 09:18
          收起回复


            来自Android客户端15楼2016-08-18 15:38
            回复
              function f_add_hh(rp,ap)
              if(ls(ap)==1)
              f_qk(ap)
              else
              f_xj(ap)
              endif
              variable fa=fopen(ap,"a","utf_8")
              variable fr=fopen(rp,"r","utf_8")
              variable k=0
              do
              k=k+1
              variable str=freadline(fr)
              if(and(str!="",strsub(str,0,2)!="//"))
              fprintf(fa,"%s\n",str+" //☞第"+k)
              elseif(and(str!="",strsub(str,0,2)=="//"))
              fprintf(fa,"%s\n",str+" ☞第"+k)
              endif
              until(feof(fr))
              fclose(fr)
              fclose(fa)
              //f_gm(ap,rp)
              endf


              来自Android客户端16楼2016-08-18 15:41
              回复
                如果,文加行号_new.mfps中出错了,要增加或减少行数,怎样将"//第1"这样的文字去掉,重新编排,加行数


                来自Android客户端17楼2016-08-18 16:00
                收起回复
                  2025-12-24 10:04:18
                  广告
                  不感兴趣
                  开通SVIP免广告
                  有三种格式需变动,
                  ①第21行:文尾去掉 "☞第21"
                  ②第1~9行:文尾去掉"//☞第1"~"//☞第9"
                  ③第10~20行及第22行:文尾去掉"//☞第10"~"//☞第20"及"//☞第22"
                  ①中无"//"
                  ②③字符长度不同
                  得用3个if


                  来自Android客户端18楼2016-08-18 16:20
                  收起回复
                    if <1>//☞第21
                    variable h=split(str,"☞")
                    取h[0]
                    elseif <2>//第1~20,第22
                    variable g=split(str,"//")
                    取g[0]
                    endif


                    来自Android客户端19楼2016-08-18 16:41
                    回复


                      来自Android客户端20楼2016-08-18 17:01
                      回复
                        function f_delete_hh(rp,ap)
                        if(ls(ap)==1)
                        f_qk(ap)
                        else
                        f_xj(ap)
                        endif
                        variable fa=fopen(ap,"a","utf_8")
                        variable fr=fopen(rp,"r","utf_8")
                        variable k=0
                        do
                        k=k+1
                        variable str=freadline(fr)
                        if(and(str!="",strsub(str,0,2)!="//"))
                        fprintf(fa,"%s\n",split(str," //")[0])
                        elseif(and(str!="",strsub(str,0,2)=="//"))
                        fprintf(fa,"%s\n",split(str," ☞")[0])
                        endif
                        until(feof(fr))
                        fclose(fr)
                        fclose(fa)
                        //f_gm(ap,rp)
                        endf


                        来自Android客户端21楼2016-08-18 19:16
                        收起回复
                          据目录选择打开文档
                          help
                          @language:simplified_chinese
                          f_mulu_r(path,hzui)
                          例如:
                          f_mulu_r("/storage/sdcard1/Books",".txt")
                          endh
                          //主程序:打开文件夹,显示目录,选择并打开文件
                          function f_mulu_r(path,hzui)
                          //variable path="/storage/sdcard1/Books"
                          //variable hzui=".txt" or ".mfps"
                          if(ls("tem")==1)
                          f_qk("tem")
                          else
                          f_xj("tem")
                          endif
                          variable list=list_files(path)
                          variable k=0
                          do
                          k=k+1
                          if(strsub(list[k-1],strlen(list[k-1])-strlen(hzui),strlen(list[k-1]))==hzui)
                          f_storage_f("tem",list[k-1])
                          endif
                          until(k==size(list)[0])
                          f_add_hh("tem","temp")
                          variable fp=fopen("temp","r","utf_8")
                          do
                          variable str=freadline(fp)
                          printf("%s\n",str)
                          until(feof(fp))
                          fclose(fp)
                          pause("\n回车键继续…")
                          variable h=input("\n?(hh),(u or g):","s")
                          variable hh=split(h,",")[0]
                          variable sm=split(h,",")[1]
                          variable encoding=iff(sm=="u","utf_8",sm=="g","gbk","")
                          variable fp1=fopen("temp","r","utf_8")
                          do
                          variable t=split(freadline(fp1)," //☞第")
                          if(t[1]==hh)
                          f_xst(path+"/"+t[0],encoding)
                          endif
                          until(feof(fp1))
                          fclose(fp1)
                          endf



                          来自Android客户端22楼2016-08-19 13:30
                          回复
                            //相关子程序:显示文本内容
                            function f_xst(s,p)
                            variable fp=fopen(s,"r",p)
                            print("☞{当前的文本是:"+s+"}\n")
                            variable k=0
                            do
                            k=k+1
                            variable str=freadline(fp)
                            print("№"+k+":📖"+str)
                            //pause("\n回车键继续…")
                            pause("")//无需提示,直接回车键
                            until(feof(fp))
                            fclose(fp)
                            endf
                            //相关子程序:存储文件
                            function f_storage_f(s,str)
                            variable fp=fopen(s,"a","UTF-8")
                            fprintf(fp,"%s\n",str)
                            fclose(fp)
                            endf
                            //相关子程序:新建文件
                            function f_xj(s)
                            return create_file(s)
                            endf
                            //相关子程序:清空文字内容
                            function f_qk(s)
                            variablefe = fopen(s, "w","UTF-8")
                            fprintf(fe,"%s","")
                            fclose(fe)
                            endf
                            //相关子程序:段尾填加行号
                            function f_add_hh(rp,ap)
                            if(ls(ap)==1)
                            f_qk(ap)
                            else
                            f_xj(ap)
                            endif
                            variable fa=fopen(ap,"a","utf_8")
                            variable fr=fopen(rp,"r","utf_8")
                            variable k=0
                            do
                            k=k+1
                            variable str=freadline(fr)
                            if(and(str!="",strsub(str,0,2)!="//"))
                            fprintf(fa,"%s\n",str+" //☞第"+k)
                            elseif(and(str!="",strsub(str,0,2)=="//"))
                            fprintf(fa,"%s\n",str+" ☞第"+k)
                            endif
                            until(feof(fr))
                            fclose(fr)
                            fclose(fa)
                            endf


                            来自Android客户端24楼2016-08-19 14:01
                            回复
                              2025-12-24 09:58:18
                              广告
                              不感兴趣
                              开通SVIP免广告
                              //改进显示内容,增加退出命令
                              function f_xst(s,p)
                              variable fp=fopen(s,"r",p)
                              print("☞{当前的文本是:"+s+"}\n")
                              variable k=0
                              do
                              k=k+1
                              variable str=freadline(fp)
                              print("№"+k+":📖"+str)
                              variable w=input("\n☞","s")
                              //无输入换行继续,输入其它终止
                              if(w!="")
                              break
                              else
                              continue
                              endif
                              until(feof(fp))
                              fclose(fp)
                              endf


                              来自Android客户端25楼2016-08-19 15:03
                              收起回复