Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to Recurisvely Find same File in Folder and SubFolder and overwrite from Source

Status
Not open for further replies.

dannymakie

Technical User
Feb 21, 2013
1
0
0
GB
Script to find all instances of thunderbird address book file in users folder and overwrite from source. There seems to be a access denied on line 13 (If aItem.Name = "impab.mab", i have full rights and the script is running as myself.

Any IDeas?

Dim wshShell, fso, objDir
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strDir = "C:\Users"
strSource = "%software%\tbcontacts\impab.mab"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)

Sub getInfo(pCurrentDir)

For Each aItem In pCurrentDir.Files
On Error Resume Next
If aItem.Name = "impab.mab" Then
wscript.Echo "Found " & aItem.Path
strTar = aItem.Path
fso.CopyFile strSource, strTar, True
'do file manip, copy delete here
End If
Next

For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Path & " passing recursively"
getInfo(aItem)
Next


End Sub
 
Try:
Code:
On Error Resume Next
For Each aItem In pCurrentDir.Files
   If Err.Number = 0 Then
      If aItem.Name = "impab.mab" Then
         wscript.Echo "Found " & aItem.Path
         strTar = aItem.Path
         fso.CopyFile strSource, strTar, True
         'do file manip, copy delete here
      End If
   End If
Next

Just be aware that you will not see any runtime errors while getInfo sub is running
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top