我正在编写一个VBScript来将文件从源文件复制到目标文件。它可以从源复制到目标,但是如果我们试图将文件覆盖到目标,并且如果任何用户在目标中打开同一个文件,它就不会覆盖它。
注意:用户打开文件具有写访问权。
有人可以帮忙吗?以下是该功能,但必须删除也在目的地打开的文件。
Sub Clear_All_Files_And_SubFolders_In_Folder()
'Delete all files and subfolders
'Be sure that no file is open in the folder
Dim FSO As Object
Dim MyPath As String
Set FSO = CreateObject("scripting.filesystemobject")
MyPath = "C:\Users\Ron\Test" '<< Change
If Right(MyPath, 1) = "\" Then
MyPath = Left(MyPath, Len(MyPath) - 1)
End If
If FSO.FolderExists(MyPath) = False Then
MsgBox MyPath & " doesn't exist"
Exit Sub
End If
On Error Resume Next
'Delete files
FSO.DeleteFile MyPath & "\*.*", True
'Delete subfolders
FSO.DeleteFolder MyPath & "\*.*", True
On Error GoTo 0
End Sub