0

我希望在不指定文件夹的情况下从 E:\ 驱动器中获取所有文件。我希望脚本只抓取 E: 驱动器中的所有文件。这是我的脚本。我尝试了多种方法来编写它,但无法让它工作。这是我的脚本,它通过抓取驱动器内的文件夹来工作。第二个是我尝试修改以使其正常工作的那个。任何帮助将不胜感激。

    Set fso = CreateObject("Scripting.FileSystemObject")

testfolder = ".\allpictures"
'fso.CreateFolder(testfolder)

CopyFiles fso.GetFolder("C:\Users\virix\Desktop\mytest") 

Sub CopyFiles(fldr)
  For Each f In fldr.Files
    basename  = fso.GetBaseName(f)
    extension = fso.GetExtensionName(f)
    If LCase(extension) = "jpg" or LCase(extension) = "jpeg" Then
      dest  = fso.BuildPath(testfolder, f.Name)
      count = 0
      Do While fso.FileExists(dest)
        count = count + 1
        dest  = fso.BuildPath(testfolder, basename & "_" & count & "." _
          & extension)
      Loop
      f.Copy dest
    End If
  Next

  For Each sf In fldr.SubFolders
    CopyFiles sf
  Next
End Sub

这是我修改的,但无法开始工作。

Set fso = CreateObject("Scripting.FileSystemObject")

testfolder = ".\allpictures"
'fso.CreateFolder(testfolder)

StartCopy fso.GetDrive("E:\")

Sub StartCopy(fldr)
  For Each f In fldr.Files 
    basename  = fso.GetBaseName(f)
    extension = fso.GetExtensionName(f)
    If LCase(extension) = "jpeg" or LCase(extension) = "jpg" Then
      dest  = fso.BuildPath(testfolder, f.Name)
      count = 0
      Do While fso.FileExists(dest)
        count = count + 1
        dest  = fso.BuildPath(testfolder, basename & "_" & count & "." _
          & extension)
      Loop
      f.Copy dest
    End If
  Next

  For Each sf In fldr.SubFolders
    StartCopy sf
  Next
End Sub
4

1 回答 1

0

尝试这个 :

Set fso = CreateObject("Scripting.FileSystemObject")

testfolder = ".\allpictures"
'fso.CreateFolder(testfolder)

StartCopy fso.GetFolder("E:\")

Sub StartCopy(fldr)
  For Each Subfolder in fldr.SubFolders
  For Each f In fldr.Files 
    basename  = fso.GetBaseName(f)
    extension = fso.GetExtensionName(f)
    If LCase(extension) = "jpeg" or LCase(extension) = "jpg" Then
      dest  = fso.BuildPath(testfolder, f.Name)
      count = 0
      Do While fso.FileExists(dest)
        count = count + 1
        dest  = fso.BuildPath(testfolder, basename & "_" & count & "." _
          & extension)
      Loop
      f.Copy dest
    End If
  Next
   StartCopy Subfolder
  Next

  For Each sf In fldr.SubFolders
    StartCopy sf
  Next
End Sub
于 2013-02-11T02:45:21.267 回答