2013/02/13

Simple Filer

This is a simple filer. You can view file and directorylist and delete it.

Files created by the user in the program are continue to remain inside until you delete in the program.So I made this for removing unnecessary your files.

However, it can delete the files only created by the user except program.
The BASIC program can be deleted from the selection list.

This is only for iPad within portlait because of screen size.

//------------------------------------------------
/* ファイルの一覧表示と削除を行うプログラム
/*  サンプルのようでいて、実は実用プログラムである
/* File list display and delete program
/* This is sample program and this is practical program actually.
//------------------------------------------------
// for X-BASIC for iOS v2.1

// 初期化 / initialize
font("IPAGothic")
int fzenhan
int WX=64:if deviceType()<>1 then WX=48
int WY=width(WX,,fzenhan)
int xw=1:/* 全角1文字の桁数 / zenkaku 1 character columus
if fzenhan then xw=2

// タッチキー位置 / touch key area
int tx=WX-20:// <WX/2にすること
int ty=3
//
// 画面作成 / screen make
int lns=20:// 表示行数 / display lines
if lns>=WY-2 then lns=WY-2
makeScreen()
//
// 全ファイルリストを得る / get all file list
dim str fileList(256):// ()内は扱える最大ファイル数
int allcnt
str ext="":// 全ファイルを示す拡張子 / extension for all files
//
// 初期ファイル検索 / initial file search
int top:// 表示している先頭行要素番号:fileList(top)
  // 表示範囲は(top)〜(top+lns-1)
int cur:// カーソル位置:0〜lns-1
searchFiles(ext)
tcolor(-THWHITE,0,0,255)
int page=0
int fafterMessage=NO
//
repeat
 int top0=top,cur0=cur
 int fdel=NO
 str ext0=ext
 //
 int ky=inkey()
 switch ky
  // カーソル移動 / cursor move
  case '8'
   // カーソル上 / cursor up
   if fafterMessage then messageDisp("")
   if cur=0 then {
    if top>0 then top=top-1
   } else {
    cur=cur-1
   }
   break
  case '2'
   // カーソル下 / cursor down
   if fafterMessage then messageDisp("")
   if cur=lns-1 then {
    if top+lns<allcnt then top=top+1
   } else {
    if top+cur<allcnt-1 then cur=cur+1
   }
   break
  // ページ単位移動 / page move
  case '4'
   // 前ページ / prev. page
   if fafterMessage then messageDisp("")
   if allcnt>lns then {
    // ページ切り替えが可能なとき / When paging is enabled
    top=top-(lns-1):// 1行残す / left 1 line
    if top<0 then top=0 else page=page-1
   }
   break
  case '6'
   // 次ページ / next page
   if fafterMessage then messageDisp("")
   if allcnt>lns then {
    // ページ切り替えが可能なとき / When paging is enabled
    top=top+(lns-1):// 1行残す / left 1 line
    if top+lns>allcnt then {
     top=allcnt-lns
    } else {
     page=page+1
    }
   }
   break

  // 削除 / delete
  case 'd'
   if fafterMessage then messageDisp("")
   allcnt=allcnt-1
   str fname=fileList(top+cur)
   int ret
   str title$,errmes$
   dim str mn$(1)
   if isLocalizeJapan() then {
    mn$(0)="いいえ"
    mn$(1)="はい"
   } else {
    mn$(0)="NO"
    mn$(1)="YES"
   }
   if fname[strlen(fname)-1]='/' then {
    // ディレクトリだったとき
    if isLocalizeJapan() then {
     title$="このディレクトリを削除しますか?"
     errmes$="削除できません(空でない)"
    } else {
     title$="Delete this directory ?"
     errmes$="Can't delete(Not empty)"
    }
    if selectMenu(title$,mn$)=1 then {
     // ただし、空ディレクトリでないと削除できない
     if rmdir(fname)=0 then {
      fdel=YES:// 表示も変更が必要
     } else {
      messageDisp(errmes$+":"+fname)
     }
    }
   } else {
    // ファイルだった時
    if isLocalizeJapan() then {
     title$="このファイルを削除しますか?"+chr$(DISP_CTRL_LF)+fname
     errmes$="削除できません"
    } else {
     title$="Delete this file ?"
     errmes$="Can't delete"
    }
    if pathExtension(fname)="bas" then {
     // .basファイルは消せないようにしておく(プログラムを削除するのはプログラム選択メニューから)
     // Disable to delete .bas file (if you will do, do in program select menu)
     messageDisp(errmes$+"(.bas):"+fname)
     break
    }
    if selectMenu(title$,mn$)=1 then {
     if fdelete(fname)=0 then {
      fdel=YES:// 表示も変更が必要
     } else {
      messageDisp(errmes$+":"+fname)
     }
    }
   }
   break

  // 拡張子変更 / change extension
  case 'j'
   if fafterMessage then messageDisp("")
   ext="jpg"
   break
  case 'p'
   if fafterMessage then messageDisp("")
   ext="png"
   break
  case 'a'
   if fafterMessage then messageDisp("")
   ext=""
   break

  default
   break
 endswitch
 if ext<>ext0 or fdel=YES then {
  // 拡張子変更 / extension changed
  // またはファイルの数が変わった / Or the number of files is changed
  // ファイルの再検索をするが、このページの先頭は変更しなくても良い
  int top1=top
  int cur1=cur
  searchFiles(ext)
  if top1+cur1>=allcnt then {
   if cur1>0 then cur=cur1-1:// 一番後ろを消したときは、1つ上に上げる。でもそれが最上行を消すものなら、前ページに移動する・・・のは大変なので、最初から表示しなおし
  } else {
   // 新しいページにまだ収まるとき
   top=top1
   cur=cur1
  }
  // ページは変わらないけど、再表示は必要
  printList()
 }
 if top<>top0 then {
  // ページが変わる / page changed
  printList()
  fdel=NO
 } else {
  if cur<>cur0 then {
   // カーソル位置が変わった / cursor moved
   printList1(cur0) // 元の位置を反転解除 / non-reverse old position
   printList1(cur)  // 新しい位置を反転 / revese new position
  }
 }
until ky='!'
end

//------------------------------------------------
// 関数 / functions
//------------------------------------------------

func printKeys(x;int,y;int)
     //  012345678901 *2
 locate(x,y+0):print "┏━┓┏━┓┏━┓┏━┓"
 locate(x,y+1):print "┃←┃┃↑┃┃↓┃┃→┃"
 locate(x,y+2):print "┗━┛┗━┛┗━┛┗━┛"
endfunc

func makeScreen()
 // タッチキー / touch key
 dim int touchNo(10) :// タッチエリア番号 / touch area number
 int touchallcnt  :// タッチエリア数   / the number of touch area
 //
 int x=0
 int y=1+lns+1
 printKeys(x,y)

 int i=0
 touchNo(inc(i))=setTouchArea(textX2Gx(x+ 0),textY2Gy(y),textX2Gx(xw*3),textY2Gy(3),'4',YES,  125,0,5,100)
 touchNo(inc(i))=setTouchArea(textX2Gx(x+ 6),textY2Gy(y),textX2Gx(xw*3),textY2Gy(3),'8',YES,  125,0,5,100)
 touchNo(inc(i))=setTouchArea(textX2Gx(x+12),textY2Gy(y),textX2Gx(xw*3),textY2Gy(3),'2',YES,  125,0,5,100)
 touchNo(inc(i))=setTouchArea(textX2Gx(x+18),textY2Gy(y),textX2Gx(xw*3),textY2Gy(3),'6',YES,  125,0,5,100)
 touchallcnt=i

 // ファンクションキー / fucntion key
 str exit$,ext$,prev$,next$,del$
 if isLocalizeJapan() then {
  exit$="終了"
  ext$="全て"
  prev$="前頁"
  next$="後頁"
  del$="削除"
 } else {
  exit$="exit"
  ext$="all"
  prev$="Prev"
  next$="Next"
  del$="Del"
 }
 setFunctionKey(0,prev$,'4')
 setFunctionKey(1,next$,'6')
 setFunctionKey(2,"   ",'?')
 setFunctionKey(3,del$ ,'d')
 setFunctionKey(4,"   ",'?')
 setFunctionKey(5,"jpg",'j')
 setFunctionKey(6,"png",'p')
 setFunctionKey(7,ext$ ,'a')
 setFunctionKey(8,"   ",'?')
 setFunctionKey(9,exit$,'!')

 setFunctionKeyBackgroundImage("funcBack.png")
 displayFunctionKeyAll(YES,YES):// v2.0
endfunc

func messageDisp(mes;str)
 locate(0,lns+1)
 if len(mes)=0 then {
  print chr$(DISP_CTRL_CLEARLINE) 
  fafterMessage=NO:// メッセージ表示してない / Message is not displaying
 } else {
  print mes
  fafterMessage=YES:// メッセージ表示中 / Now message is displaying
 }
endfunc

//------------------------------------------------

func printList1(i;int)
// 1行表示 / 1line display
 locate(0,1+i)
 if i=cur then tatrb(ATRB_REVERSE):// 選択行 / selected line
 if top+i<allcnt then {
  print using "###:";top+i;
  print fileList(top+i);
 // print lastPathComponent(fileList(top+i));
  if i=cur then tatrb(ATRB_NORMAL)
 }
 print chr$(DISP_CTRL_CLEARLINE):// 行末まで消す / clear to end of line
endfunc

func printList()
// 画面内表示 / display in screen
 int i
 int max=lns
 for i=0 to max-1
  printList1(i)
 next
 locate(WX-10,0):print "page=";page
endfunc

func searchFiles(ext;str)
 // 新しく表示し直すので各種ポインターをリセット
 top=0 :// 表示している先頭行要素番号:fileList(top)
    // 表示範囲は(top)〜(top+lns-1)
 cur=0 :// カーソル位置:0〜lns-1
 //
 allcnt=files(fileList,"",ext,YES,FILES_ALL)
 cls()
 printKeys(0,1+lns+1)
 //
 locate(0,0)
 if isLocalizeJapan() then {
  print "拡張子=";ext,,
  print "ファイル数=";allcnt
 } else {
  print "extension=";ext,,
  print allcnt;" files"
 }
 printList()
endfunc

//------------------------------------------------


Zip archive file : XBetc.zip

No comments:

Post a Comment