VBScript将指定文件(例如* .txt)从文件夹(和子文件夹)移动到指定位置

时间:2018-01-11 20:23:56

标签: file vbscript directory

我有这个脚本用于访问根文件夹和根目录的所有子文件夹。该脚本用于查找所有PDF文件并将其复制到指定的文件夹中。不幸的是,有些事情是不对的,因为我在尝试获取当前文件夹并使用fso.CopyFile curDir & "\*.pdf", "C:\users"复制文件时收到错误。

Set objFSO = CreateObject("Scripting.FileSystemObject")

objStartFolder = "C:\Users\jula\Desktop\docs"

Set objFolder = objFSO.GetFolder(objStartFolder)
WScript.Echo objFolder.Path

Set colFiles = objFolder.Files
WScript.Echo "Start, I think"

ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)
    For Each Subfolder In Folder.SubFolders
        'displaying the current folder it's searching in
        WScript.Echo Subfolder.Path

        Set objFolder = objFSO.GetFolder(Subfolder.Path)

        Set colFiles = objFolder.Files

        For Each objFile In colFiles
            'obtaining the curent directory name
            curDir = objFSO.GetParentFolderName(WScript.ScriptFullName)
            objFSO.CopyFile curDir & "\*.pdf", "C:\users'\jula\Desktop\folderToMoveIn"
            WScript.Echo objFile.Name
        Next

        WScript.Echo

        ShowSubFolders Subfolder
    Next
End Sub

0 个答案:

没有答案