通过 VBScript (VBS) 使用通配符移动未知数量的文件
Move unknown number of files using wildcard via VBScript (VBS)
我正在尝试使用通配符将一个或多个文件从一个目录移动到另一个目录:
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("Z:\somepath\somefile_*_A.xlsm") Then
filesys.MoveFile "Z:\somepath\somefile_*_A.xlsm", "Z:\destpath\"
End If
而且它不起作用...
备注:
我不想移动这些目录中的其他文件。我想移动使用通配符返回的所有文件。必须使用 VBS。
链接:
VBscript to move files from one directory to another
https://msdn.microsoft.com/en-us/library/2wcf3ba6%28v=vs.84%29.aspx
我不能将通配符传递给 findfiles。
你可以自己检查一下
For Each file In filessys.GetFolder("Z:\somepath").Files
If( <do your checks on file.Name, might be a regex or a simple string compare>) Then
filesys.MoveFile file, "Z:\destpath\"
End If
Next
根据您对文件格式的了解程度,检查 rightmost characters if they are always "_A.xlsm" or you can use a regular expression
可能就足够了
Function ShowFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
这来自帮助。 FSO 中没有通配符。你必须自己做。因此,测试 f1.name 是否满足您的要求,然后复制该文件。
我正在尝试使用通配符将一个或多个文件从一个目录移动到另一个目录:
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("Z:\somepath\somefile_*_A.xlsm") Then
filesys.MoveFile "Z:\somepath\somefile_*_A.xlsm", "Z:\destpath\"
End If
而且它不起作用...
备注:
我不想移动这些目录中的其他文件。我想移动使用通配符返回的所有文件。必须使用 VBS。
链接:
VBscript to move files from one directory to another
https://msdn.microsoft.com/en-us/library/2wcf3ba6%28v=vs.84%29.aspx
我不能将通配符传递给 findfiles。 你可以自己检查一下
For Each file In filessys.GetFolder("Z:\somepath").Files
If( <do your checks on file.Name, might be a regex or a simple string compare>) Then
filesys.MoveFile file, "Z:\destpath\"
End If
Next
根据您对文件格式的了解程度,检查 rightmost characters if they are always "_A.xlsm" or you can use a regular expression
可能就足够了Function ShowFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
这来自帮助。 FSO 中没有通配符。你必须自己做。因此,测试 f1.name 是否满足您的要求,然后复制该文件。