返回列表 上一主題 發帖

[發問] 請教大大如果目錄存在略過不要複製,如何改,謝謝

[發問] 請教大大如果目錄存在略過不要複製,如何改,謝謝

本帖最後由 wufonna 於 2019-7-5 20:48 編輯
  1. Option Explicit
  2. Sub Ex()
  3.     Dim myPath As String, myFile As String, myname As String, n As Integer, strPath As String
  4.     myPath = ThisWorkbook.Path & "\" 'myPath = ThisWorkbook.Path 檔案路
  5.     myFile = "*.JPG"
  6.     myname = Dir(myPath & myFile)

  7.     Do While myname <> ""
  8.         n = n + 1
  9. '       Name myPath & myname As myPath & "FS" & Format(n, "00000") & ".jpg"
  10. strPath = myPath & Replace(myname, ".jpg", "")



  11.    MkDir strPath
  12. '錯誤
  13. 'If Len(Dir("c:\test\aaa", vbDirectory)) = 0 Then
  14. ' MkDir "c\test\aaa"
  15. 'End If
  16. '
  17.         myname = Dir
  18.     Loop
  19.     MsgBox n
  20. End Sub
複製代碼

mkdirtest.zip (271.2 KB)

本帖最後由 wufonna 於 2019-7-6 20:18 編輯

回復 1# wufonna
改這樣可以,請教大大
  1. Option Explicit
  2. '批次改目錄
  3. Sub Ex()
  4.     Dim myPath As String, myFile As String, myname As String, n As Integer, strPath As String
  5.     Dim S() As String, i As Integer, m As Variant
  6.     myPath = ThisWorkbook.Path & "\" 'myPath = ThisWorkbook.Path 檔案路
  7.     myFile = "*.JPG"
  8.     myname = Dir(myPath & myFile)
  9.     i = 0

  10.     Do While myname <> ""
  11.         n = n + 1
  12. '       Name myPath & myname As myPath & "FS" & Format(n, "00000") & ".jpg"
  13. strPath = myPath & Replace(myname, ".jpg", "")

  14.     ReDim Preserve S(i)
  15.     S(i) = strPath
  16.   ' Debug.Print S(i)
  17.          myname = Dir

  18. i = i + 1
  19.     Loop


  20.     For Each m In S
  21. '    Debug.Print m

  22.      If Len(Dir(m, vbDirectory)) = 0 Then
  23.       MkDir m
  24.      End If
  25.     Next
  26.    
  27.    ' MsgBox n
  28. End Sub
複製代碼

TOP

        靜思自在 : 【時間成就一切】時間可以造就人格,可以成就事業,也可以儲積功德。
返回列表 上一主題