将除特定文件以外的所有文件移动到文件夹vbscript

将除特定文件以外的所有文件移动到文件夹vbscript,vbscript,Vbscript,我正试图使用vbscript将我的所有文件移动到另一个文件夹中,但不知何故,我似乎无法正确执行。我已经执行了代码,但我不希望的文件名也会移动到我创建的文件夹中。你能帮我吗 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder("C:\Users\Users\Desktop\Other Files\Excel Files") If objFolder.Name <

我正试图使用vbscript将我的所有文件移动到另一个文件夹中,但不知何故,我似乎无法正确执行。我已经执行了代码,但我不希望的文件名也会移动到我创建的文件夹中。你能帮我吗

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder("C:\Users\Users\Desktop\Other Files\Excel 
Files")

If objFolder.Name <> "TestResults.xlsx" Then

objFSO.Movefile "C:\Users\Users\Desktop\Other Files\Excel Files\*", 
"C:\Users\Users\Desktop\Sample Folder"

End If
Set objFSO=CreateObject(“Scripting.FileSystemObject”)
设置objFolder=objFSO.GetFolder(“C:\Users\Users\Desktop\Other Files\Excel
文件“)
如果objFolder.Name为“TestResults.xlsx”,则
objFSO.Movefile“C:\Users\Users\Desktop\Other Files\Excel Files\*”,
“C:\Users\Users\Desktop\Sample文件夹”
如果结束
我已经执行了代码,但我不想要的文件名也会移动到我创建的文件夹中

这是因为您正在移动所有文件,因为您使用了*

虽然对象只引用文件夹,但代码中很少有问题,比如
If objFolder.Name“TestResults.xlsx”

然后你移动了所有的文件-你必须遍历文件夹并过滤掉那些不能移动的文件

试试下面的代码

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\Users\Desktop\Other Files\Excel Files").Files

For Each objFile In objFolder
    If objFile.Name <> "TestResults.xlsx" Then
        objFSO.MoveFile objFile.Path, "C:\Users\Users\Desktop\Sample Folder\"
    End If
Next
Set objFSO=CreateObject(“Scripting.FileSystemObject”)
设置objFolder=objFSO.GetFolder(“C:\Users\Users\Desktop\Other Files\Excel Files”).Files
对于objFolder中的每个objFile
如果objFile.Name为“TestResults.xlsx”,则
objFSO.MoveFile objFile.Path,“C:\Users\Users\Desktop\Sample Folder\”
如果结束
下一个
我已经执行了代码,但我不想要的文件名也会移动到我创建的文件夹中

这是因为您正在移动所有文件,因为您使用了*

虽然对象只引用文件夹,但代码中很少有问题,比如
If objFolder.Name“TestResults.xlsx”

然后你移动了所有的文件-你必须遍历文件夹并过滤掉那些不能移动的文件

试试下面的代码

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Users\Users\Desktop\Other Files\Excel Files").Files

For Each objFile In objFolder
    If objFile.Name <> "TestResults.xlsx" Then
        objFSO.MoveFile objFile.Path, "C:\Users\Users\Desktop\Sample Folder\"
    End If
Next
Set objFSO=CreateObject(“Scripting.FileSystemObject”)
设置objFolder=objFSO.GetFolder(“C:\Users\Users\Desktop\Other Files\Excel Files”).Files
对于objFolder中的每个objFile
如果objFile.Name为“TestResults.xlsx”,则
objFSO.MoveFile objFile.Path,“C:\Users\Users\Desktop\Sample Folder\”
如果结束
下一个

谢谢!我很难弄明白这个问题。。。我在互联网上做了一些研究,但似乎什么都不管用。。。非常感谢:)谢谢!我很难弄明白这个问题。。。我在互联网上做了一些研究,但似乎什么都不管用。。。非常感谢:)