• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

VBScript to enumerate folders

I need to traverse the folders on a network share to place a file in the roaming profile for each user.  I know how to do everything I need to do except traverse the fodlers.  Assuming I have the netowrk share \\server\profiles which contains a folder for each user, how can I iterate through each folder?  I need to check for an existing file in each folder "objFSO.FileExists("test.txt")"
0
rkeith2412
Asked:
rkeith2412
  • 3
  • 3
1 Solution
 
rlandquistCommented:
How about something like:
Replace the echoing of the subfolder name with the search and copy you need to do.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\TEST")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
 Wscript.Echo objSubfolder.Name
Next

Open in new window

0
 
rkeith2412Author Commented:
I am trying to use the following script but get an acccess denied when actually trying to copy the file.  If I comment out the CopyFile and repalce it with a MsgBox I get a list of all the folders.  I am a domain admin and can manually copy the file.  WHat am I doing wrong?

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\cargo\profiles")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
    If objFSO.FileExists("\\cargo\profiles\"&objSubfolder.Name&"\windows\SFW.ini") Then
        objFSO.CopyFile "\\cargo\public\Summit\SFW.ini","\\cargo\profiles\"&objSubfolder.Name&"\windows\SFW.ini",true
    End If
Next 

Open in new window

0
 
rkeith2412Author Commented:
Awesome!!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rlandquistCommented:
I take it you figured out the problem?
0
 
rkeith2412Author Commented:
No, I just moved on to another solution.  I never got over the Access Denied error.  If you could provide any insight that could help in the future, it would be great.
0
 
rlandquistCommented:
With the copy command, for the destination, you should not include the file name.
objFSO.CopyFile "\\cargo\public\Summit\SFW.ini","\\cargo\profiles\"&objSubfolder.Name&"\windows\",true

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now