1

Basically, I need a script to move files to another folder that have been accessed and modified.

I'm new to scripting, so this may be a simple problem, but I'm stumped. Here's the error I'm getting:

Script: C:\Users\bmcwilliams\Desktop\pssitest.vbs

Line: 17

Char: 10

Error: File already exists

Code: 800A003A

Source: Microsoft VBScript runtime error

The destination folder is empty, so I'm not sure what's going on.

Below is the code I have. It's modified from the code listed in this post:

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")

Any ideas? Any input is greatly appreciated. Thanks!

4

2 回答 2

1

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

file.Move destinationpath +"\" + file.name
于 2012-10-11T20:31:59.847 回答
0

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

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

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

于 2012-10-11T20:36:10.703 回答