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

copying range of folders

Status
Not open for further replies.

bobojones

Programmer
May 31, 2005
1
US
I am wanting to copy some folders from a network directory. The names of the folder would fall in a specific number range. ie 12345678-12346178. How could I run a script that would search teh root folder ald look to see if there is are any folder with names that fall within the above range and if found copy the folder and contents to a local drive.

Thanks
Bob
 
Use the FileSystemObject to recursively (a function the calls itself) traverse the folder while comparing the name of the folder to the range.

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
function searchDir(strDir)
   set objFolder = objFSO.GetFolder(strDir)
   for each objSubFolder in objFolder.SubFolders
      strResults = strResults & vbNewLine & searchDir(objSubFolder.Path)
      if ((objSubFolder.Name >= "12345678") AND (objSubFolder.Name <= "12346178") then
         strResults = strResults & objSubFolder.Path & vbNewLine
      end if
   next
   searchDir = strResults
end function

strDir = "C:\temp"
msgbox searchDir(strDir)

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top