VBS脚本,以获取所有图像并为重复项添加值



我希望在不指定文件夹的情况下从E:\驱动器中获取所有文件。我希望脚本只抓取E:驱动器中的所有文件。这是我的剧本。我试过多种方法来写它,但都没能成功。这是我的脚本,它通过抓取驱动器中的文件夹来工作。第二个是我试图修改以使其工作的那个。如有任何帮助,我们将不胜感激。

    Set fso = CreateObject("Scripting.FileSystemObject")
testfolder = ".allpictures"
'fso.CreateFolder(testfolder)
CopyFiles fso.GetFolder("C:UsersvirixDesktopmytest") 
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

试试这个:

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

相关内容

  • 没有找到相关文章

最新更新