vbscript - How to avoid "permission denied" when copying damaged files? -
i write vbscript copy file e drive c drive. there many system files , damaged files in e drive, when copy these files, script stop. method pass or skip these files when script running?
the code copy folders e drive c drive
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 each uu in f set ws = wscript.createobject("scripting.filesystemobject") ws.copyfolder uu,path & "\"
for each uu in f set ws = wscript.createobject("scripting.filesystemobject") ws.copyfolder hd & uu,path1 end if next
becomes set ws = wscript.createobject("scripting.filesystemobject")
on error resume next each uu in f ws.copyfolder uu.path, path1 if err.number <> 0 err.clear next
plus unknown reason have end if
.
this basics can work on recreate folder structure (this dumps files in 1 folder).
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" each thing in f.subfolders msgbox thing.path if err.number <> 0 msgbox err.description err.clear end if each thingy in thing.files msgbox thingy.path thingy.copy(folder2 & "\" & thingy.name) if err.number <> 0 msgbox err.description err.clear end if next next
only took line , edit on line recreate file structure.
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") each thing in f.subfolders fso.createfolder(folder2 & "\" & thing.name) if err.number <> 0 log.writeline thing.path & err.description err.clear end if each thingy in thing.files thingy.copy(folder2 & "\" & thing.name & "\" & thingy.name) if err.number <> 0 log.writeline thingy.path & err.description err.clear end if next next
Comments
Post a Comment