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

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

只看楼主收藏回复

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")
f_xst("temp")
//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客户端26楼2016-08-19 19:28
收起回复
    citingspace ::mfunc::file_operate
    function f_xst(s,p,num)
    variable fp=fopen(s,"r",p)
    if(num==1)
    variable str=freadline(fp)
    printf("№%d:",k)
    printf("📖%s\n",str)
    endif
    if(num>=2)
    variable k=1
    do
    k=k+1
    variable str=freadline(fp)
    until(k==num)
    variable sr=freadline(fp)
    printf("№%d:",k)
    printf("📖%s\n",sr)
    endif
    fclose(fp)
    endf
    function f_jx_r(s,p,st,ed)
    for variable num=st to ed
    using citingspace ::mfunc::file_operate
    f_xst(s,p,num)
    next
    endf
    endcs


    来自Android客户端27楼2016-08-19 21:21
    收起回复
      2025-12-24 16:48:35
      广告
      不感兴趣
      开通SVIP免广告


      来自Android客户端31楼2016-08-19 21:49
      收起回复
        function f_operate_hh(rp,ap,c)
        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(c=="a")
        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
        elseif(c=="d")
        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
        else
        return
        endif
        until(feof(fr))
        fclose(fr)
        fclose(fa)
        //f_gm(ap,rp)
        endf


        来自Android客户端34楼2016-08-20 20:29
        收起回复


          来自Android客户端35楼2016-08-20 20:30
          回复
            function f_pdtxt_encoding(txt_path)
            variable s1=f_tp(txt_path,"utf_8",1)
            variable encoding=iff(conv_str_to_ints(strsub(s1,0,1))<=40912,"utf_8","gbk")
            return encoding
            endf


            来自Android客户端38楼2016-08-21 08:12
            收起回复
              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")
              f_xst("temp")
              variable hh=input("\n?输入(行号:hh):","s")
              variable fp1=fopen("temp","r","utf_8")
              do
              variable t=split(freadline(fp1)," //☞第")
              if(t[1]==hh)
              f_xst(path+"/"+t[0],f_pdtxt_encoding(path+"/"+t[0]))
              endif
              until(feof(fp1))
              fclose(fp1)
              endf


              来自Android客户端40楼2016-08-21 08:38
              收起回复
                //相关子程序:提取文本的某行文字内容
                function f_tp(s,p,line)
                variable fp=fopen(s,"r",p)
                if(line==1)
                variable str=freadline(fp)
                return str
                endif
                if(line>=2)
                variable k=1
                do
                k=k+1
                variable str=freadline(fp)
                until(k==line)
                variable st=freadline(fp)
                return st
                endif
                fclose(fp)
                endf


                来自Android客户端41楼2016-08-21 08:45
                回复
                  2025-12-24 16:42:35
                  广告
                  不感兴趣
                  开通SVIP免广告
                  citingspace ::mfunc::file_operate
                  function f_xst_txt(s,num)
                  variable p=f_pdtxt_encoding(s)
                  variable fp=fopen(s,"r",p)
                  variable k=0
                  do
                  k=k+1
                  variable str=freadline(fp)
                  until(k==num)
                  variable sr=freadline(fp)
                  printf("№%d:📖%s",k,sr)
                  fclose(fp)
                  endf
                  function f_continue_read(s,st,ed)
                  variable p=f_pdtxt_encoding(s)
                  for variable num=st to ed
                  using citingspace ::mfunc::file_operate
                  f_xst_txt(s,num)
                  variable w=input("\n☞","s")//换行继续,其它终止
                  if(w!="")
                  break
                  else
                  continue
                  endif
                  next
                  endf
                  endcs


                  来自Android客户端42楼2016-08-21 12:47
                  收起回复
                    回到第25楼问题,打开并显示记事本书签(目录),选择目录行号,继续阅读,此时
                    需调用f_jsb与f_continue_read两个子程序


                    来自Android客户端45楼2016-08-21 13:20
                    回复
                      //子程序:显示文本内容
                      function f_xs_t(s,num)
                      variable p=f_pdtxt_encoding(s)
                      variable fp=fopen(s,"r",p)
                      variable k=0
                      do
                      k=k+1
                      variable str=freadline(fp)
                      until(k==num)
                      variable sr=freadline(fp)
                      printf("№%d:📖%s",k,sr)
                      fclose(fp)
                      endf


                      来自Android客户端46楼2016-08-23 12:05
                      回复
                        //主程序:继续阅读
                        function f_jx_rd()
                        if(ls("temp_bookmark")==1)
                        f_qk("temp_bookmark")
                        else
                        f_xj("temp_bookmark")
                        endif
                        f_edit_hh("bookmark","temp_bookmark","a")
                        f_xst("temp_bookmark")
                        variable hh=input("选写行号:","s")
                        variable fp1=fopen("temp_bookmark","r","utf_8")
                        do
                        variable t=split(freadline(fp1)," //☞第")
                        variable st=evaluate(split(t[0],",")[1])
                        variable s=split(t[0],",")[0]
                        if(t[1]==hh)
                        variable p=f_pdtxt_encoding(s)
                        for variable num=st to +inf
                        f_xs_t(s,num)
                        variable w=input("\n☞","s")//换行继续,其它终止
                        if(w!="")
                        variable fbk=fopen("bookmark","a","utf_8")
                        fprintf(fbk,"%s\n",s+","+num)
                        //fprintf(fbk,"%s\n","\""+s+"\""+","+num)
                        fclose(fbk)
                        print("已添加书签 !" )
                        break
                        else
                        continue
                        endif
                        next
                        endif
                        until(feof(fp1))
                        fclose(fp1)
                        endf


                        来自Android客户端47楼2016-08-23 12:06
                        收起回复
                          回到第42楼,跳出循环,添加书签,可将w相关语句改为:
                          variable w=input("\n☞","s")//换行继续,其它终止
                          if(w!="")
                          variable fbk=fopen("bookmark","a","utf_8")
                          fprintf(fbk,"%s\n",s+","+num)
                          //fprintf(fbk,"%s\n","\""+s+"\""+","+num)
                          fclose(fbk)
                          print("已添加书签 !" )
                          break
                          else
                          continue
                          endif
                          next
                          endif


                          来自Android客户端49楼2016-08-23 12:21
                          回复
                            弄两个快捷键玩玩



                            来自Android客户端50楼2016-08-23 12:32
                            回复
                              2025-12-24 16:36:35
                              广告
                              不感兴趣
                              开通SVIP免广告
                              楼主,本吧官方Q群需要你这样的大神加入。群号:475501676


                              来自Android客户端51楼2016-10-08 20:15
                              回复