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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search unlimited subfolders

Status
Not open for further replies.

kracksmith

Technical User
Jul 5, 2004
14
US
This script searches for anything on the root folder but won't search sub directiories. i know i need to search for recursive but i'm not very good with scripting. Can somebody help in adding the recursion?


Dim sOriginFolder, sDestinationFolder, sFile, oFSO, sAllowedExt, bMove, sMorC
Set oFSO = CreateObject("Scripting.FileSystemObject")
sOriginFolder = "C:\Documents and Settings\administrator.DOMAIN1\Desktop\folder1"
sDestinationFolder = "C:\Documents and Settings\administrator.DOMAIN1\Desktop\folder2"
aAllowedExt = Array("rpt","ppt")
'Set bMove to False to copy, or True to move
bMove = False
For Each sFile In oFSO.GetFolder(sOriginFolder).Files
For Each sFileExtension In aAllowedExt
If UCase(oFSO.GetExtensionName(sFile)) = UCase(sFileExtension) Then
If Not oFSO.FileExists(sDestinationFolder & "\" & oFSO.GetFileName(sFile)) Then
Select Case bMove
Case True
sMorC = "moved"
oFSO.GetFile(sFile).Move sDestinationFolder & "\"
Case False
sMorC = "copied"
oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True
End Select
End If
End If
Next
Next
WScript.Echo "Copying : All the files have been " & sMorC & " to " & sDestinationFolder
 
You didn't even look at the FAQ area ?
faq329-5515

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top