ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦h¼h¸ê®Æ§¨´M§äÀɮתº°ÝÃD

[µo°Ý] ¦h¼h¸ê®Æ§¨´M§äÀɮתº°ÝÃD

¥»©«³Ì«á¥Ñ ui123 ©ó 2014-3-6 23:00 ½s¿è

¦U¦ì¤j¤j¡A¹J¨ì¤@­ÓÃøÃD¬O³o¼Ëªº:
¥­®ÉÀɮ׳£·|©ñ¦b¤@­Ó¸ê®Æ§¨ªº²Ä¤@¼h¡A¦ý©w®É·|¦³¤H¥h±N³o¨ÇÀɮ׫ö¦~¤ë¥hÂk¦ì
¦pªG¦b²Ä¤@¼h§ä¤£¨ìÀɮסA´N­n©¹¤U¤@¼h¥h§ä­Ó­Ó¸ê®Æ§¨¬ÝÀɮצb­þ¸Ì...¥u·|¦s¦b¦b¨ä¤¤¤@­Ó¸ê®Æ§¨¡A¦ý¤£ª¾¹D¦b­þ¤@­Ó
½d¨Ò:¤ñ¤è§Ú­n§ä¦W¬°fileªºÀɮסA§ä¨ì«áµM«á¥´¶}¦¹ÀÉ®×(¨S§ä¨ìÅã¥Ü"¨S§ä¨ì¦¹ÀÉ®×")¡A¦pªþ¥ó¡C
¥Ø«e¥u·|¨Ï¥Î³æ¼hdir

New folder.rar (6.28 KB)

¬Ý¨ì¤@­Ó¼ÐÃD¬O³o¼Ëªº:
"Excel VBA to list files in folder and subfolder with path to .txt file"
¦p¤Uºô§}:
http://stackoverflow.com/questions/20219362/excel-vba-to-list-files-in-folder-and-subfolder-with-path-to-txt-file

§Ú¸Õ¹L¥L·|¦C¥X©Ò¦³¸ê®Æ§¨ªº¦WºÙ¡A¦ý¦³­Ó¤p¤pºÃ°Ý¡A­n«ç»ò§Q¥Îdir¥h´M§ä³o²M³æµM«á¥´¶}­nªºÀÉ®×?¦³¤j¤j¥i¥H±Ð§Ú¤@¤U¶Ü? ¥Ñ°J·PÁÂ^^

    Sub go()
        ShowFolderList ("C:\temp")
    End Sub

    Sub ShowFolderList(folderspec)
        Dim fs, f, f1, fc, s, sFldr
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set fc = f.SubFolders
         For Each f1 In fc
            ShowFolderList f1
        Next
        Set fc = f.Files
        For Each f1 In fc
            Debug.Print folderspec & f1.Name
        Next
    End Sub

TOP

¦^´_ 2# ui123


   http://gb.twbts.com/index.php/topic,1877.0.html
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 3# Hsieh

¿Ë·Rªºª©¥D±z¦n~
§Ú¦³³s¶i¥hÅo->Excelµ{¦¡°Ï 1877.0 html ¬O¤°»ò? ¤£À´¡A·P®¦^^

TOP

¥»©«³Ì«á¥Ñ Hsieh ©ó 2014-3-9 10:20 ½s¿è

Dir ¨ç¼Æ - °ò¥»ªºÀÉ®×/¸ê®Æ§¨Åª¨ú¤è¦¡
Sub ¦C¥XÀÉ®×()
path1 = "C:\Temp\*.*"
file1 = Dir(path1): r = 1
Do While file1 <> ""
¡@Cells(r, 1) = file1
¡@r = r + 1
¡@file1 = Dir '¨ú±o¤U¤@­ÓÀɦW
Loop
End Sub

Dir °ò¥»À³¥Î½d¨Ò
¹ï¤@­Ó¤w³Q¨ä¥L¹q¸£(«D¥»¾÷)¥H¸ê·½¦@¨É¤è¦¡¶}±ÒªºxlsÀÉ¡A¦³¨S¦³¤°»ò¤èªk¨Ó°»´ú©Î´y­z¥¦ªºÄݩʩΪ¬ºA¡A¥Hªí¥Ü¥¦¬O¤@­Ó¡u¥Ø«e¤w³Q¶}±Ò¨Ï¥Î¤¤¡vªºÀÉ®×??

¥H¤Uªº¥¨¶°·|§â¥»¾÷©M«ü©w¥Ø¿ý¤U¨Ï¥Î¤¤ªºxlsÀɦC¥X¡C

Sub CheckFile()
Application.ScreenUpdating = False
Range("A1") = "¥»¾÷¤w¶}±ÒÀÉ®×"
For Each book In Workbooks
¡@GoSub 1: Cells(r, 1) = book.FullName
Next
mypath = "C:\": GoSub 1
myfile = Dir(mypath & "*.xls")
Cells(r, 1) = "¥L¤H¨Ï¥Î¤¤ÀÉ®×"
Do While myfile <> "" ' °õ¦æ°j°é
¡@GoSub 1: myfilename = mypath & myfile
¡@Workbooks.Open myfilename
¡@If ActiveWorkbook.ReadOnly Then Cells(r, 1) = myfilename
¡@Workbooks(myfile).Close
¡@myfile = Dir ' ´M§ä¤U¤@­ÓÀÉ®×
Loop: Exit Sub
1 r = Application.WorksheetFunction.CountA(Columns(1)) + 1: Return
End Sub

µù¡G¸ê®Æ§¨¤À¨É¼Ò¦¡À³³]©w¬°¡u§¹¾ã¡v¡A§_«h°»´ú¤£¨ì¡C 

Dir ¶i¶¥À³¥Î½d¨Ò
¦C¥X«ü©w¥Ø¿ý¤§¤U©Ò¦³ªº¤l¸ê®Æ§¨¤º®e¡C

Sub list_and_link1()
Dim ary() As String, rw As Long
rw = 1: i = 0
path1 = "C:\myArticle\"
file1 = Dir(path1 & "*.*", vbDirectory) '¥u³B²z¸ê®Æ§¨
Do While file1 <> ""
¡@If file1 <> "." And file1 <> ".." And _
¡@¡@ GetAttr(path1 & file1) = vbDirectory Then
¡@¡@ i = i + 1
¡@¡@ ReDim Preserve ary(i)
¡@¡@ ary(i) = file1
¡@End If
¡@file1 = Dir
Loop
For i = 1 To UBound(ary)
¡@ Cells(rw, 1) = ary(i)
¡@ rw = rw + 1
¡@ GetSubs path1 & ary(i) & "\", rw, 1
Next i
file1 = Dir(path1 & "*.*")
Do While file1 <> ""
¡@'¦¹¨Ò¥u¦C¥XÀɦW, §A¥i¼g¤W­n°µªº°Ê§@
¡@Cells(rw, 1) = file1
¡@rw = rw + 1
¡@file1 = Dir
Loop
End Sub

Sub GetSubs(sPath As String, rw As Long, ilevel As Long)
Dim ary1() As String
ReDim ary1(1)
sName = Dir(sPath, vbDirectory)
Do While sName <> ""
¡@If sName <> "." And sName <> ".." And _
¡@¡@ GetAttr(sPath & sName) = vbDirectory Then
¡@¡@ ary1(UBound(ary1)) = sName
¡@¡@ ReDim Preserve ary1(UBound(ary1) + 1)
¡@End If
¡@sName = Dir
Loop
For i = 1 To UBound(ary1) - 1
¡@ Cells(rw, ilevel + 1) = ary1(i)
¡@ rw = rw + 1
¡@ GetSubs sPath & ary1(i) & "\", rw, ilevel + 1
Next i
sName = Dir(sPath & "*.*")
Do While sName <> ""
¡@Cells(rw, ilevel + 1) = sName
¡@rw = rw + 1
¡@sName = Dir
Loop
End Sub

--------------------------------------
Dir ¨ç¼Æªº¯SÂI¡G
¥Î©ó¨ú±oÀɮשΥؿýªº¦WºÙ¡A¾A¦X°ò¥»ªº»Ý¨D¡C
FileSystem object ªº¯SÂI¡G
¦]¬°¥¦¬Oª«¥ó¡A¾Ö¦³³\¦hÄÝ©Ê©M¤èªk¡A¥i¥H°µ§óÆF¬¡ªº¹B¥Î¡C

Àɮפñ¹ï / ¥Ø¿ý¾Þ§@ (GetFolder)
¦sÀɮɦp¦ó±oª¾¨ä¥L´X­Ó¸ê®Æ§¨¸Ì¤w¦³¬Û¦P¦WºÙªºÀɮצs¦b (¤w¦s¦bÀɮצ³¥i¯à¬OÁôÂÃ)??

¥i¦b¥¨¶°¤¤¨Ï¥Î FileSystem ª«¥ó¨Ó·j´M¤ñ¹ï, ·|¥]§tÁôÂÃÀÉ.
°²³]³o¤­­Ó¸ê®Æ§¨¦ì©ó C:\My Documents¡C

Sub ÀˬdÀÉ®×( )
¡@ÀɦW = InputBox("½Ð¿é¤JÀɦW (¥]§t°ÆÀɦW)¡G")
¡@If ÀɦW = "" Then Cancel = True: Exit Sub
¡@Set fs = CreateObject("Scripting.FileSystemObject")
¡@Set sf = fs.GetFolder("C:\My Documents").SubFolders
¡@For Each f In sf
¡@¡@For Each f1 In f.Files
¡@¡@¡@If f1.Name = ÀɦW Then
¡@¡@¡@¡@MsgBox ÀɦW & " ¤w¦s¦b©ó " & f.Name & " ¸ê®Æ§¨!"
¡@¡@¡@¡@a = 1: Exit For
¡@¡@¡@End If
¡@¡@Next
¡@Next
¡@If a = 1 Then Cancel = True
End Sub

­Y¤´·Q±oª¾¸ÓÀɮ׬O§_¬°ÁôÂÃÀÉ, ¥i¨Ï¥Î¤U¦Cµ{¦¡½X :
If f1.Attributes And 2 Then MsgBox "¸ÓÀɮ׬°ÁôÂÃÀÉ!"

§PÂ_Àɮ׬O§_¦s¦b (FileExists)
¦p¦ó§PÂ_±ý¶}±ÒªºÀɮ׬O§_¦s¦b¡A­Y¦s¦b«h¶}±Ò¤§¡A­Y¤£¦s¦b«h¶}±Ò·sÀɨéR¦W¬°«ü©wªºÀɦW¡A­Y¸ÓÀɮפw¸g¶}±Ò«h¨Ï¸ÓÀɮצ¨¬°§@¥Î¤¤ªºÀɮסH 

1 ÀɦW = InputBox("½Ð¿é¤JÀɦW¡G")
2 If ÀɦW = "" Then Exit Sub
3 For Each win In Windows
4¡@ If UCase(win.Caption) = UCase(ÀɦW) Then x = True: Exit For
5 Next: If x Then win.Activate: Exit Sub
6 Set fs = CreateObject("Scripting.FileSystemObject")
7 If Not fs.FileExists(ÀɦW) Then
'8¡@ Set newfile = Workbooks.Add
'0¡@ newfile.SaveAs ÀɦW
8¡@ Workbooks.Add.SaveAs ÀɦW
9 Else: Workbooks.Open ÀɦW
0 End If

[»¡©ú]
1 Åã¥Ü¹ï¸Ü®Ø, ¿é¤JÀɦW (­n§t°ÆÀɦW)
2 ¦pªG¨S¿é¤J©Î«ö¤F¨ú®ø«h¶Ç¦^ªÅ¦r¦ê, µ²§ô¥¨¶°
3 ¹ï¤w¶}±Òªº¨C­Óµøµ¡(ÀÉ®×)°µ°j°é¤ñ¹ï
4 ­Yµøµ¡¼ÐÃD = ¿é¤JªºÀɦW«h³]ÅÜ¼Æ x = True, µ²§ô°j°é
¡@(¨Ï¥Î UCase ¨ç¼ÆÂà´«¬°¤j¼g¥H«K©ó¤ñ¹ï)
5 ­Y x ¬° True «h¨Ï¸ÓÀɮצ¨¬°¨Ï¥Î¤¤µøµ¡
6 «Ø¥ß¤@­Ó FileSystem ª«¥ó, ¥H§@ºÏºÐÀɮ׳B²z
7 ­Y«ü©wªºÀɮפ£¦s¦b
8 ¶}·sÀɮרæs¬°«ü©wªºÀɦW
9 §_«h¶}±Ò«ü©wªºÀÉ®×
0 µ²§ô If §PÂ_

[µù]
¡E¬°»¡©ú¤§«K¦Ó¥[¤Wµ{¦¡¦æ¸¹, ¤@¯ë¬O¤£»Ý­nªº
¡E½d¨Ò°w¹ï"¥Ø«e"¸ê®Æ§¨, ¦³»Ý­n½Ð¦Û¦æ¥[¤W¸ô®|

Dir / FileSystem À³¥Î¤ñ¸û
¦³¤j¶qªºExcelÀÉ, ¨ä¤¤­n§â¬Y¨Ç¦r¦ê§ï¦¨§Oªº¦r¦ê, ¤ñ¦p©Ò¦³ªºaaa­n§ï¦¨bbb¡C

°²³]Àɮ׳£©ñ¦b D:\Temp ¸ê®Æ§¨¤§¤U, 
­n§â¨ä¤¤©Ò¦³ Excel Àɤ¤ªº aaa ¨ú¥N¬° bbb.
ºÏºÐ/Àɮתº³B²z¤£¥~¥G Dir¨ç¼Æ ©M Filesystem Object ¨âºØ¤èªk.

¤@. ¨Ï¥Î Dir ¨ç¼Æ
Sub ¨ú¥N¤@¤j°ï()
¡@p = "D:\Temp\"
¡@f = Dir(p & "*.xls")
¡@Do While f <> ""
¡@¡@Workbooks.Open p & f
¡@¡@For Each sh In Worksheets
¡@¡@¡@sh.Cells.Replace "aaa", "bbb", xlPart
¡@¡@Next
¡@¡@ActiveWorkbook.Close True '¦sÀɨÃÃö³¬
¡@¡@f = Dir
¡@Loop
End Sub

¤G. ¨Ï¥Î Filesystem Object
Sub ¨ú¥N¤@¤j°ï()
¡@Set fs = CreateObject("Scripting.FileSystemObject")
¡@Set fd = fs.GetFolder("D:\Temp") '¨ú±o¸ê®Æ§¨
¡@For Each f In fd.Files
¡@¡@If fs.GetExtensionName(f.Name) = "xls" Then '¨ú±o°ÆÀɦW
¡@¡@Workbooks.Open f.Path
¡@¡@For Each sh In Worksheets
¡@¡@¡@sh.Cells.Replace "aaa", "bbb", xlPart
¡@¡@Next
¡@¡@ActiveWorkbook.Close True
¡@¡@End If
¡@Next
End Sub
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 5# Hsieh

ª©¤j§Ú¦³¬Ý§¹§APOªº¤å¡ASub list_and_link1 ¥i¥H¦C¥X©Ò¦³ÀɮצW
----------------------------------------------------------------------------------------------------------
¥t¥~¤]§ä¤F¤@ºØ¤èªk¡A¥¦¥i¥HÀ°§Ú§ä¥X©Ò¦³ÀɮצWºÙ¡A¦ý¦³­Ó¤p¤p°ÝÃD¡A
¦pªGSheet1ªºRange("A1") ¬O·j´MªºÀɦW¡A¨Ò¦p:file(¦p¥DÃD¤¤ªºªþ¥ó)¡A¦p¦ó¦b·j´M¨ì«á¥´¶}¥L???·PÁ±z^^

Public Sub TestListDir()
    Worksheets(1).Cells(2, 1).Activate
    Call listDir("C:\Users\ui\Desktop\New folder\", 1)
End Sub

Public Sub listDir(strPath As String, lngSheet As Long)
Dim strFn As String
Dim strDirList() As String
Dim lngArrayMax, x As Long
lngArrayMax = 0
strFn = Dir(strPath & "*.*", 23)
While strFn <> ""
    If strFn <> "." And strFn <> ".." Then
        If (GetAttr(strPath & strFn) And vbDirectory) = vbDirectory Then
            lngArrayMax = lngArrayMax + 1
            ReDim Preserve strDirList(lngArrayMax)
            strDirList(lngArrayMax) = strPath & strFn & "\"
        Else
            ActiveCell.Value = strPath & strFn
            Worksheets(lngSheet).Cells(ActiveCell.Row + 1, 1).Activate
        End If
    End If
    strFn = Dir()
Wend
If lngArrayMax <> 0 Then
    For x = 1 To lngArrayMax
        Call listDir(strDirList(x), lngSheet)
    Next
End If
End Sub

TOP

¦U¦ì¤j¤j¡Aµ¹±z­Ì¦^³ø¥Ø«eª¬ªp

¼È®É¤è®×:
¥Ø«eµLªk¸Ñ¨M"Dir¦b¦Usubfolder§ä¨ìÀÉ®×´N¶}°_¨Ó(ÀÉ®×¥u¦s¦b¤@­Ó¸ê®Æ§¨)"
©Ò¥H²{¦b¼È®ÉÀ³À³±¹¬I¬°:  ¥ý¦C¥X©Ò¦³ªºÀɮצW¡AµM«á·j¥X­nªºÀɮצW+§¹¾ã¦ì¸m¡AµM«á¥´¶}¥¦~
---------------------------------------------------------------------------------------------
¥Ã¤[¹ïµ¦:
¦p¦³¤H·|"Dir¦Usubfolder"µM«á¥´¶}§ä¨ìªºÀɮתº¸Ü¡A½Ð¤£¥O«ü±Ð¡A·PÁÂ~^^
PS:­n§äªºÀɮצW·|©ñ¦bA1Àx¦s®æ

TOP

¦^´_ 7# ui123
ÀɦW©ñ¦bA1
´Nµy§ï¤@¤U´N¥i¥H¤F
°õ¦ælist_and_link1
  1. Sub list_and_link1()
  2. Dim ary() As String, rw As Long
  3. rw = 1: i = 0
  4. path1 = "C:\temp\" '²Ä¤@¼h¸ê®Æ§¨
  5. file1 = Dir(path1 & "*.*", vbDirectory) '¥u³B²z¸ê®Æ§¨
  6. Do While file1 <> ""
  7.   If file1 <> "." And file1 <> ".." And _
  8.      GetAttr(path1 & file1) = vbDirectory Then
  9.      i = i + 1
  10.      ReDim Preserve ary(i)
  11.      ary(i) = file1
  12.   End If
  13.   file1 = Dir
  14. Loop
  15. For i = 1 To UBound(ary)
  16.    GetSubs path1 & ary(i) & "\", rw, 1
  17. Next i
  18. End Sub

  19. Sub GetSubs(sPath As String, rw As Long, ilevel As Long)
  20. Dim ary1() As String
  21. ReDim ary1(1)
  22. sname = Dir(sPath, vbDirectory)
  23. Do While sname <> ""
  24.   If sname <> "." And sname <> ".." And _
  25.      GetAttr(sPath & sname) = vbDirectory Then
  26.      ary1(UBound(ary1)) = sname
  27.      ReDim Preserve ary1(UBound(ary1) + 1)
  28.   End If
  29.   sname = Dir
  30. Loop
  31. For i = 1 To UBound(ary1) - 1
  32.    rw = rw + 1
  33.    GetSubs sPath & ary1(i) & "\", rw, ilevel + 1
  34. Next i
  35. sname = Dir(sPath & "*.*")
  36. If Dir(sPath & [A1]) = [A1] Then
  37.    Workbooks.Open sPath & [A1] '¶}±ÒÀÉ®×
  38. End
  39. End If
  40. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 8# Hsieh

¤j¤j±z¦n,§Ú·Q³z¹L±zªºµ{¦¡½X,¦Û°Ê§ä¨ì[­Ó¤H¥¨¶°¬¡­¶Ã¯]ªº¦ì¸m

¦ý¹J¨ì2­Ó°ÝÃD
1.(Åv­­°ÝÃD),¦]­Ó¤H¥¨¶°¬¡­¶Ã¯À³¸Ó¤£·|©ñ¨ìÅv­­ªº¸ê®Æ§¨¸Ì­±,¦]¦¹§Ú¼g¤@­ÓON ERROR RESUME NEXT ¸õ¹L
2.§ä¤£¨ì[XLSTART]¸ê®Æ§¨...WHY?
  1. Sub list_and_link1()
  2.     Dim ary() As String, rw As Long
  3.     rw = 1: i = 0
  4.     path1 = "C:\" '²Ä¤@¼h¸ê®Æ§¨
  5.     file1 = Dir(path1 & "*.*", vbDirectory) '¥u³B²z¸ê®Æ§¨
  6.     Do While file1 <> ""
  7.       If file1 <> "." And file1 <> ".." And _
  8.          GetAttr(path1 & file1) = vbDirectory Then
  9.          i = i + 1
  10.          ReDim Preserve ary(i)
  11.          ary(i) = file1
  12.       End If
  13.       file1 = Dir
  14.     Loop
  15.     For i = 1 To UBound(ary)
  16.        GetSubs path1 & ary(i) & "\", rw, 1
  17.     Next i
  18. End Sub

  19. Sub GetSubs(sPath As String, rw As Long, ilevel As Long)
  20.     Dim ary1() As String
  21.     ReDim ary1(1)
  22.     On Error Resume Next
  23.     sname = ""
  24.     sname = Dir(sPath, vbDirectory)
  25.     On Error GoTo 0
  26.     Do While sname <> ""
  27.       If sname <> "." And sname <> ".." And _
  28.          GetAttr(sPath & sname) = vbDirectory Then
  29.          ary1(UBound(ary1)) = sname
  30.          ReDim Preserve ary1(UBound(ary1) + 1)
  31.       End If
  32.       sname = Dir
  33.     Loop
  34.     For i = 1 To UBound(ary1) - 1
  35.        rw = rw + 1
  36.        GetSubs sPath & ary1(i) & "\", rw, ilevel + 1
  37.       If ary1(i) = "XLSTART" Then
  38.             Sheets("LOG").[E1] = sPath & ary1(i)
  39.             End
  40.       End If
  41.     Next i
  42. End Sub
½Æ»s¥N½X
PKKO

TOP

¦^´_ 9# PKKO
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. 'FileSystemObject ª«¥ó" ´£¨Ñ¹ï¹q¸£Àɮרt²Îªº¦s¨ú¡C
  3. Sub Ex()
  4.     Dim Fs As Object, F As Object
  5.     Set Fs = CreateObject("Scripting.FileSystemObject").GetDRIVE("C:")
  6.     Set Fs = Fs.ROOTFOLDER.SubFolders '®Ú¥Ø¿ý\¸ê®Æ§¨ª«¥ó¶°¦X
  7.     For Each F In Fs
  8.        °Æµ{¦¡ F.Path
  9.     Next
  10. End Sub
  11. Private Sub °Æµ{¦¡(¸ê®Æ§¨ As String)
  12.     Dim Fs As Object, F As Object
  13.     Set Fs = CreateObject("Scripting.FileSystemObject")
  14.     '*** ¦p¸ê®Æ§¨¤U¦³¤l¸ê®Æ§¨ ¦A©I¥s³o°Æ.µ{¦¡ ***
  15.     '©I¥s µ{¦¡ªº°j°é
  16.     On Error Resume Next  '¦³¿ù»~¸õ¹L
  17.     For Each F In Fs.GetFolder(¸ê®Æ§¨).SubFolders
  18.         If Err = 0 Then  '¨S¦³¿ù»~®É
  19.             If InStr(F, "XLSTART") Then
  20.                 MsgBox F
  21.                 End
  22.             End If
  23.         End If
  24.         °Æµ{¦¡ F.Path
  25.     Next
  26. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

        ÀR«ä¦Û¦b : ·O´d¨S¦³¼Ä¤H¡A´¼¼z¤£°_·Ð´o¡C
ªð¦^¦Cªí ¤W¤@¥DÃD