【问题标题】:VBScript that Moves modified files to another folder将修改后的文件移动到另一个文件夹的 VBScript
【发布时间】:2012-10-11 20:20:03
【问题描述】:

基本上,我需要一个脚本来将文件移动到另一个已被访问和修改过的文件夹。

我是脚本新手,所以这可能是一个简单的问题,但我很难过。这是我得到的错误:

脚本:C:\Users\bmcwilliams\Desktop\pssitest.vbs

线路:17

字符:10

错误:文件已存在

代码:800A003A

来源:Microsoft VBScript 运行时错误

目标文件夹是空的,所以我不确定发生了什么。

下面是我的代码。它是根据这篇文章中列出的代码修改的:

How to move files from a directory to another directory based on file size

' use a default source path
dim sourcepath: sourcepath = "C:\users\bmcwilliams\Desktop\TestUncompleted"

' use a default destination path
dim destinationpath: destinationpath = "C:\users\bmcwilliams\Desktop\TestCompleted"

dim fso: set fso = CreateObject("Scripting.FileSystemObject")
dim sourcefolder: set sourcefolder = fso.GetFolder(sourcepath)

' loop through each file in the directory, compare size property against
' the limit and copy as appropriate
dim file, count: count = 0
for each file in sourcefolder.Files
    dim createDate: createDate = file.DateCreated
    dim modifyDate: modifyDate = file.DateLastModified
    if createDate <> modifyDate Then
         file.Move destinationpath
         count = count + 1
    end if
next

WScript.Echo("complete: " & count & " file(s) moved")

有什么想法吗?非常感谢任何输入。谢谢!

【问题讨论】:

    标签: vbscript move datecreated modified-date


    【解决方案1】:

    您正在复制到新位置,但未提供文件的新名称。要解决此问题,请将 \ 和文件名附加到目标路径。

    file.Move destinationpath +"\" + file.name
    

    【讨论】:

      【解决方案2】:

      如果移动文件的目标路径是文件夹而不是完整路径(包括目标文件名),则它必须有一个尾随反斜杠:

      destinationpath = "C:\users\bmcwilliams\Desktop\TestCompleted\"
      

      否则Move 操作会检测到目标(文件夹)已经存在,因此会失败。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多