Vbscript 如何避免;“拒绝许可”;复制损坏的文件时?
我编写了一个VBScript,将文件从E驱动器复制到C驱动器。E驱动器中有许多系统文件和损坏的文件,因此复制这些文件时,脚本将停止。脚本运行时,有没有传递或跳过这些文件的方法 代码是将所有文件夹从E驱动器复制到C驱动器Vbscript 如何避免;“拒绝许可”;复制损坏的文件时?,vbscript,Vbscript,我编写了一个VBScript,将文件从E驱动器复制到C驱动器。E驱动器中有许多系统文件和损坏的文件,因此复制这些文件时,脚本将停止。脚本运行时,有没有传递或跳过这些文件的方法 代码是将所有文件夹从E驱动器复制到C驱动器 Const hd = "E:\" Const cd = "C:\" Dim path Sub GenPath() path = cd End Sub Sub GenFolder() Set objFso = CreateObject("Scripting.FileS
Const hd = "E:\"
Const cd = "C:\"
Dim path
Sub GenPath()
path = cd
End Sub
Sub GenFolder()
Set objFso = CreateObject("Scripting.FileSystemObject")
objFso.CreateFolder path
Set objFso = Nothing
End Sub
Set fso=WScript.CreateObject("scripting.filesystemobject")
Set fs=fso.GetFolder("E:\")
Set f=fs.SubFolders
For Each uu In f
Set Ws = WScript.CreateObject("Scripting.filesystemobject")
Ws.CopyFolder uu,path & "\"
变成
设置Ws=WScript.CreateObject(“Scripting.filesystemobject”)
只需要额外的一行和另一行的编辑就可以重新创建文件结构
On error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Users\David Candy\Desktop")
fso.createfolder("C:\Users\David Candy\test123")
Folder2 = "C:\Users\David Candy\test123"
Set log = fso.CreateTextFile("c:\logfile.txt")
For Each thing in f.subfolders
fso.createfolder(folder2 & "\" & thing.name)
If err.number <> 0 then
log.writeline thing.path & err.description
err.clear
End If
For Each thingy in thing.files
thingy.copy(Folder2 & "\" & thing.name & "\" & thingy.name)
If err.number <> 0 then
log.writeline thingy.path & err.description
err.clear
End If
Next
Next
出错时继续下一步
设置fso=CreateObject(“Scripting.FileSystemObject”)
设置f=fso.GetFolder(“C:\Users\David Candy\Desktop”)
创建文件夹(“C:\Users\David Candy\test123”)
Folder2=“C:\Users\David Candy\test123”
设置log=fso.CreateTextFile(“c:\logfile.txt”)
对于f子文件夹中的每一项
fso.createfolder(folder2&“\”&thing.name)
如果错误号为0,则
log.writeline thing.path&err.description
清楚
如果结束
对于thing.files中的每一项内容
复制(Folder2&“\”&thing.name&“\”&thingy.name)
如果错误号为0,则
log.writeline thingy.path和err.description
清楚
如果结束
下一个
下一个
您发布的代码已损坏,可能无法工作。请修复它。如果您需要代码方面的帮助,请发布您的代码,而不是您临时编造或从内存中键入的内容。您发布的代码甚至无法执行(至少是因为您有End If
而没有If
结尾)。发布编造的代码并寻求帮助调试它是浪费我们和您的时间。非常感谢,我尝试了它,在副本到达文件夹文档和设置之前它看起来不错,文件夹非常复杂,其中有许多系统文件夹和损坏的文件,脚本已停止,没有出现错误,没有文件复制,什么也没发生,你知道吗?再次谢谢
On Error Resume Next
For Each uu In f
Ws.CopyFolder uu.path, path1
If err.number <> 0 then err.clear
Next
On error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Users\David Candy\Desktop")
fso.createfolder("C:\Users\David Candy\test123")
Folder2 = "C:\Users\David Candy\test123"
For Each thing in f.subfolders
msgbox thing.path
If err.number <> 0 then
msgbox err.description
err.clear
End If
For Each thingy in thing.files
msgbox thingy.path
thingy.copy(Folder2 & "\" & thingy.name)
If err.number <> 0 then
msgbox err.description
err.clear
End If
Next
Next
On error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Users\David Candy\Desktop")
fso.createfolder("C:\Users\David Candy\test123")
Folder2 = "C:\Users\David Candy\test123"
Set log = fso.CreateTextFile("c:\logfile.txt")
For Each thing in f.subfolders
fso.createfolder(folder2 & "\" & thing.name)
If err.number <> 0 then
log.writeline thing.path & err.description
err.clear
End If
For Each thingy in thing.files
thingy.copy(Folder2 & "\" & thing.name & "\" & thingy.name)
If err.number <> 0 then
log.writeline thingy.path & err.description
err.clear
End If
Next
Next