|
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
andywilliams
註冊時間: 2004-10-23 文章: 111
第 1 樓
|
發表於: 星期日 一月 01, 2012 1:00 pm 文章主題: 讀取資料夾結構 |
|
|
長久想不出來的程式邏輯,在新的一年想通了,送大家當新年賀禮吧..
讀到資料夾結構,可再運用於複製.刪除..資料夾
代碼: |
TopDir = "C:\WINDOWS"
mDleve =1
CREAT cursor DirStru(Dleve N(8),DAttribute C(5),Dname C(250) )
APPEND blank
REPLACE Dleve with mDleve
REPLACE DAttribute with "D"
REPLACE Dname with Topdir
DO while .T.
SELE * from DirStru into cursor tmdir where Dleve = mDleve &&讀取第N層資料夾
IF eof()
exit && 若無下一層 結束
ENDIF
DO while !eof() && 處理下一層資料夾
gnDbcnumber =ADIR(gaDatabase, alltrim(Dname)+"\*.*","DHS")
ParentDir = alltrim(Dname)+"\"
FOR nCount = 1 TO gnDbcnumber
IF "D" $ gaDatabase(nCount,5) .and. NOT INLIST(gaDatabase(nCount,1),".","..")
SELE DirStru
APPEND blank
REPLACE Dleve with mDleve +1
REPLACE Dname with ParentDir + gaDatabase(nCount,1)
REPLACE DAttribute with gaDatabase(nCount,5)
ENDIF
ENDFOR
SELE tmdir
Skip
ENDDO
mDleve = mDleve +1
ENDDO
SELE DirStru
BROWSE
|
|
|
回頂端 |
|
|
garfield Site Admin
註冊時間: 2003-01-30 文章: 2157
第 2 樓
|
發表於: 星期一 一月 02, 2012 9:56 am 文章主題: 資料夾的清單最適合用遞迴的方式來顯示 |
|
|
* 資料夾的清單最適合用遞迴的方式來顯示
* bom 展開也是用遞迴處理最方便
代碼: |
SET ESCAPE on
mdir = 'C:\Program Files'
DO dirlist WITH mdir,0
RETURN
*****
FUNCTION dirlist
* 遞迴顯示資料夾下所有的檔名 Garfield
LPARAMETERS mdir,mdeep
* 傳來完整路徑資料夾名稱,縮排次數
LOCAL mcount,i,alist[1]
mcount =ADIR(alist, ["]+mdir+"\*.*"+["],"DHS")
FOR i=1 TO mcount
? SPACE(mdeep*3),alist[i,1]
IF 'D' $ alist[i,5]
?? '','(D)'
IF NOT ( alist[i,1]=='.' OR alist[i,1]=='..')
DO dirlist WITH mdir+'\'+alist[i,1],mdeep+1
endif
endif
next
RETURN mcount
|
_________________ 利用>>搜尋<<的功能會比問的還要快得到答案. |
|
回頂端 |
|
|
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|