Vbscript 重命名文件后将其移动到新文件夹

Vbscript 重命名文件后将其移动到新文件夹,vbscript,file-rename,file-move,Vbscript,File Rename,File Move,我需要一个VBScript来重命名文件,然后将其从一个文件夹移动到另一个文件夹。脚本当前正确重命名了文件,但我不知道重命名后如何将文件移动到新文件夹 下面是现有的脚本 Option Explicit Const SAVE_LOCATION = "\\pccit2\Int\PC\Inbox" Const strPath = "D:\Files\pak\VP\" Const StrPrefix = "VP" Dim FSO Dim FLD Dim fil Dim strOld

我需要一个VBScript来重命名文件,然后将其从一个文件夹移动到另一个文件夹。脚本当前正确重命名了文件,但我不知道重命名后如何将文件移动到新文件夹

下面是现有的脚本

Option Explicit

Const SAVE_LOCATION = "\\pccit2\Int\PC\Inbox"
Const strPath       = "D:\Files\pak\VP\"
Const StrPrefix     = "VP"

Dim FSO
Dim FLD
Dim fil
Dim strOldName
Dim strNewName

Set FSO = CreateObject("Scripting.FileSystemObject")
Set FLD = FSO.GetFolder(strPath)

For Each fil In FLD.Files
    strOldName = fil.Path
    strNewName = strPath & strPrefix & Right(strOldName, 10)
    FSO.MoveFile strOldName, strNewName
Next

For Each fil In FLD.Files
    If strNewName = 1 Then
        FSO.MoveFile "\\pccit2\Int\PC\Inbox"
    End If
Next

Set FLD = Nothing
Set FSO = Nothing
我尝试了多种方法来移动文件。以下是一些其他尝试:

If FSO.FileExists("D:\Files\pak\VP\*.*") Then
    FSO.MoveFile "D:\Files\pak\VP\*.*", "\\pccit2\Int\PC\Inbox\*.*"
End If
又一次尝试

If fil.FileExists("D:\Files\pak\VP\*.*") Then
    fil.MoveFile "D:\Files\pak\VP\*.*" , "\\pccit2\Int\PC\Inbox\*.*"
End If
用这个

dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")
fs.MoveFile "c:\myfolder\*.*","c:\anotherfolder\"
set fs=nothing
FileSystemObject
对象的方法。它需要至少两个参数(源和目标),通配符只能在源路径中使用,不能在目标路径中使用。目标路径必须是文件或文件夹路径(如果是文件夹,则在后面加反斜杠)。文件对象的相应方法是,只需一个参数(目标路径)即可调用。此外,您还可以通过一个步骤移动和重命名文件。只需使用新文件名指定目标路径

For Each fil In FLD.Files
    strNewName = FSO.BuildPath(SAVE_LOCATION, strPrefix & Right(fil.Name, 10))
    fil.Move strNewName
Next
如果要将重命名与移动分开,只需更改文件名即可重命名文件:

For Each fil In FLD.Files
    fil.Name = strPrefix & Right(fil.Name, 10)
    fil.Move SAVE_LOCATION & "\"
Next

我已经修改了脚本,正如您所指出的,我现在得到一个错误“变量未定义:'服务器'”,对于这一行:set fs=Server.CreateObject(“Scripting.FileSystemObject”),我认为他根本没有使用ASP。你是怎么想的?在常规VBScript中,您只需使用
Set fs=CreateObject(“Scripting.FileSystemObject”)
。谢谢!这是非常有帮助的,我会参考你的回应。您提供的第一个脚本非常有效。唯一的修改是在VP中添加前缀。我把它加在这里。strNewName=FSO.BuildPath(保存位置,“VP”和右侧(文件名,10))