我正在设置一个从网络上获取的vb,以将某些文件从一个文件夹复制到另一个文件夹。 除了“结束功能”之后,所有代码都正常运行。
第73行之后,该脚本不再起作用。在此之后,sleep代码以及wscript.shell不再执行。
有人可以帮忙吗?
Option Explicit
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files (x86)\VideoLAN\VLC\vlc.exe""")
WScript.sleep 5000
Dim ws
Set ws=CreateObject("WScript.Shell")
ws.Run "TASKKILL.exe /F /IM vlc.exe"
WScript.sleep 8500
Dim srcFolder, trgFolder,WshShell,UserProfilePath
Set WshShell = CreateObject("wscript.Shell")
UserProfilePath = WshShell.ExpandEnvironmentStrings("%UserProfile%")
srcFolder = "C:\Test\"
trgFolder = UserProfilePath & "\AppData\Roaming\"
CopyFilesAndFolders srcFolder, trgFolder
WScript.Quit
Sub CopyFilesAndFolders (ByVal strSource, ByVal strDestination)
Dim ObjFSO, ObjFolder, ObjSubFolder, ObjFile, files
Dim TargetPath
Set ObjFSO = CreateObject("scripting.filesystemobject")
'connecting to the folder where is going to be searched
Set ObjFolder = ObjFSO.GetFolder(strSource)
TargetPath = Replace (objFolder.path & "\", strSource, strDestination,1,-1,vbTextCompare)
If Not ObjFSO.FolderExists (TargetPath) Then ObjFSO.CreateFolder (TargetPath)
Err.clear
On Error Resume Next
'Check all files in a folder
For Each objFile In ObjFolder.files
If Err.Number <> 0 Then Exit For 'If no permission or no files in folder
On Error goto 0
If CheckToCopyFile (objFile.path, TargetPath & "\" & objFile.name) Then
objFSO.copyfile objFile.path, TargetPath & "\" & objFile.name, True
End If
Next
'Recurse through all of the subfolders
On Error Resume Next
Err.clear
For Each objSubFolder In ObjFolder.subFolders
If Err.Number <> 0 Then Exit For 'If no permission or no subfolder in folder
On Error goto 0
'For each found subfolder there will be searched for files
CopyFilesAndFolders ObjSubFolder.Path & "\", TargetPath & ObjSubFolder.name & "\"
Next
Set ObjFile = Nothing
Set ObjSubFolder = Nothing
Set ObjFolder = Nothing
Set ObjFSO = Nothing
End Sub
Sub CopyFilesAndFolders (ByVal strSource, ByVal strDestination)
Dim ObjFSO, ObjFolder, ObjSubFolder, ObjFile, files
Dim TargetPath
Set ObjFSO = CreateObject("scripting.filesystemobject")
'connecting to the folder where is going to be searched
Set ObjFolder = ObjFSO.GetFolder(strSource)
TargetPath = Replace (objFolder.path & "\", strSource, strDestination,1,-1,vbTextCompare)
If Not ObjFSO.FolderExists (TargetPath) Then ObjFSO.CreateFolder (TargetPath)
Err.clear
On Error Resume Next
'Check all files in a folder
For Each objFile In ObjFolder.files
If Err.Number <> 0 Then Exit For 'If no permission or no files in folder
On Error goto 0
If CheckToCopyFile (objFile.path, TargetPath & "\" & objFile.name) Then
objFSO.copyfile objFile.path, TargetPath & "\" & objFile.name, True
End If
Next
'Recurse through all of the subfolders
On Error Resume Next
Err.clear
For Each objSubFolder In ObjFolder.subFolders
If Err.Number <> 0 Then Exit For 'If no permission or no subfolder in folder
On Error goto 0
'For each found subfolder there will be searched for files
CopyFilesAndFolders ObjSubFolder.Path & "\", TargetPath & ObjSubFolder.name & "\"
Next
Set ObjFile = Nothing
Set ObjSubFolder = Nothing
Set ObjFolder = Nothing
Set ObjFSO = Nothing
End Sub
Function CheckToCopyFile (ByVal strSourceFilePath, ByVal strDestFilePath)
Dim oFSO, oFile, SourceFileModTime, DestFileModTime
CheckToCopyFile = True
Set oFSO = CreateObject("scripting.filesystemobject")
If Not oFSO.FileExists (strDestFilePath) Then Exit Function
Set oFile = oFSO.GetFile (strSourceFilePath)
SourceFileModTime = oFile.DateLastModified
Set oFile = Nothing
Set oFile = oFSO.GetFile (strDestFilePath)
DestFileModTime = oFile.DateLastModified
Set oFile = Nothing
If SourceFileModTime =< DestFileModTime Then CheckToCopyFile = False
Set oFSO = Nothing
End Function
WScript.sleep 8000
Dim objShell1
Set objShell1 = WScript.CreateObject( "WScript.Shell" )
objShell1.Run("""C:\Program Files (x86)\VideoLAN\VLC\vlc.exe""")
答案 0 :(得分:1)
在第23行,您有WScript.Quit
。
在开始时执行所有任务,killkill,复制文件和文件夹,然后关闭脚本。如果要运行VLC,请将objShell1.Run("""C:\Program Files (x86)\VideoLAN\VLC\vlc.exe""")
放在第23行之前。
像这样:
Dim srcFolder, trgFolder,WshShell,UserProfilePath
Set WshShell = CreateObject("wscript.Shell")
UserProfilePath = WshShell.ExpandEnvironmentStrings("%UserProfile%")
srcFolder = "C:\Test\"
trgFolder = UserProfilePath & "\AppData\Roaming\"
CopyFilesAndFolders srcFolder, trgFolder
WScript.sleep 8000
Dim objShell1
Set objShell1 = WScript.CreateObject( "WScript.Shell" )
objShell1.Run("""C:\Program Files (x86)\VideoLAN\VLC\vlc.exe""")
WScript.Quit