返回列表 上一主題 發帖

[發問] Dir 匯出指令可否排除 目錄呢?

[發問] Dir 匯出指令可否排除 目錄呢?

Dear 各位大大~

如果有該帖發問在這版不好的話,請刪除或移動之~~ 謝謝。

請問 Dir {path} >{path}.txt
匯出directories list 結構的清單的指令,能否排除目錄呢?

export directories list , but exclude xxx,xxx

我已知某些軟體,http://www.infonautics.ch/directorylistprint/  
有這種功能,但是需要licence。
想知道有沒有用指令就能做到的方式?

謝謝大家~

先用 dir /?
查dir這個指令各參數的意義

如果你要排除的是全部的子目錄
dir {path} /A-D >{path}.txt  
不包含隱藏檔
dir {path} /A-D-H >{path}.txt
只要檔名
dir {path} /A-D-H /B >{path}.txt

如果只是要排除特定目錄我就不清楚了

TOP

dir/?就可查詢全部的參數

TOP

回復 3# prin.huang


Sub P_Sample004()
    Dim myFileName As String
    myFileName = Application.InputBox(Prompt:= _
        "請輸入檔案名稱、資料夾名稱的完整路徑", Title:="確認存在")
    If Len(Dir(myFileName, vbDirectory)) > 0 Then
        If (GetAttr(myFileName) And vbDirectory) = vbDirectory Then
            MsgBox "所指定之資料夾存在。"
       Else
            MsgBox "所指定之檔案存在。"
       End If
    Else
        MsgBox "所指定之檔案或是目錄不存在。"
    End If
End Sub

Sub P_Sample003()
    Dim myPath     As String
    Dim myFileName As String
    Dim i          As Long
    myPath = ThisWorkbook.Path & "\"        '任意的資料夾
    myFileName = Dir(myPath, 0)
    Do While Len(myFileName) > 0
        Debug.Print myPath & myFileName
        myFileName = Dir()
    Loop
End Sub

TOP

        靜思自在 : 盡多少本份,就得多少本事。
返回列表 上一主題