|
发表于 2014-9-24 08:25:10
|
显示全部楼层
如下代碼供參考
- axlCmdRegister( "cam clear" 'fnCamClear)
- procedure(fnCamClear()
- let((lDeleteFile tFile x tFileName)
- ;讀取目前工作目錄下的檔案為下列的檔案並刪除
- ;*.*,* *.log *.val *.tag *.tap *.art *.jrl *.out *.afa art_aper.txt art_param.txt nc_param.txt
- ;增加刪除目錄*.run 和檔案 *_xy.txt
- lDeleteFile = nil ;存放要刪除的檔案名稱
- foreach(tFile setof(x getDirFiles(getWorkingDir()) fnCheckFile(x))
- lDeleteFile = cons(tFile lDeleteFile)
- )
- when(lDeleteFile
- foreach(tFile lDeleteFile
- tFileName = strcat(getWorkingDir() "/" tFile)
- when(isFile(tFileName) && isReadable(tFileName)
- deleteFile(tFileName)
- )
- )
- )
- ;printf("\n###On current directory *,* *,log *.val *.tag *.tap *.art *.jrl \n")
- ;printf("###nc_param.txt art_param.txt art_aper.txt *.out *.afa\n###CLEAR is finished ====\n")
- )
- )
- ;此函數的功能是判斷檔案tFileName是否為下列 ,如果是就傳回 t 否則傳回 nil
- ;*.*,* *.log *.val *.tag *.tap *.art *.jrl *.out *.afa art_aper.txt art_param.txt nc_param.txt
- procedure(fnCheckFile(tFileName)
- prog((lCheckSuffix lCheckFile lString tSuffix lResult x)
-
- lCheckSuffix = list("afa" "art" "jrl" "log" "out" "tag" "tap" "val" "txt" "run")
- lCheckFile = list("art_aper.txt" "art_param.txt" "nc_param.txt")
-
- if(stringp(tFileName) then
- tFileName = lowerCase(tFileName)
- ;判斷檔案名稱只要有 , 就傳回 t
- when(rexMatchp("," tFileName)
- return(t)
- )
- when(tFileName == "allegro.jrl" ;此檔案在Allegro執行中是不能刪除的,
- return(nil)
- )
- lString = parseString(tFileName ".")
- if(lString then
- tSuffix = cadr(lString)
- lResult = setof(x lCheckSuffix (x == tSuffix)) ;過濾後綴名稱有一樣
- if(lResult then
- ;加入判斷後綴名稱為 run ,這裡只有判斷一層子目錄而已.
- when(car(lResult) == "run"
- ;判斷是否為目錄
- when(isDir(tFileName)
- ;先取的目錄下所有的檔案和目錄,並先直接刪除後,在刪除此目錄
- bDelDirMaster = t
- foreach(tOne setof(x getDirFiles(tFileName) !((x == ".") || (x == ".."))) ;tOne = nth(0 setof(x getDirFiles(tFileName) !((x == ".") || (x == ".."))))
- tTemp = strcat(getWorkingDir() "/" tFileName "/" tOne)
- if(isDir(tTemp) then ;在判斷子目錄,並在取的目錄下所有的檔案和目錄,並先直接刪除
- bDeleteDir = t
- foreach(tSubOne setof(x getDirFiles(tTemp) !((x == ".") || (x == "..")))
- tTempSub = strcat(getWorkingDir() "/" tFileName "/" tOne "/" tSubOne)
- if(isDir(tTempSub) then
- printf("E-Cannot delete %L\n" tTempSub)
- bDeleteDir = nil
- else
- when(isFile(tTempSub)
- deleteFile(tTempSub)
- )
- )
- )
- when(bDeleteDir
- deleteDir(tTemp)
- )
- else
- ;判斷為檔案
- when(isFile(tTemp)
- deleteFile(tTemp)
- )
- )
- )
- deleteDir(tFileName)
- )
- return(nil)
- )
- when(car(lResult) == "txt"
- lResult = setof(x lCheckFile (x == tFileName)) ;過濾檔案名稱有一樣
- unless(lResult
- when(rexMatchp("_xy$" car(lString)) ;判斷檔案名稱為*_xy.txt
- return(t)
- )
- )
- )
- if(lResult then
- return(t)
- else
- return(nil)
- )
- else
- return(nil)
- )
- else
- return(nil)
- )
- else
- return(nil)
- )
- )
- )
复制代码 |
评分
-
查看全部评分
|