none
Need help with this vb script RRS feed

  • Question

  • Hi All,

    I am trying to get this script working. It run and give me the sub directory name for a particular directory. It works fine up to this.( which was the original script I found on the web). Now I am trying to add little more command. I want to copy some file to this sub directory. Here is t the code

    'showfolderlist <dirextory that you want to list>
    
    showfolderlist "c:\windows\system32\GroupPolicy\GroupPolicyUsers"
    
    'The Showfolderlist procedure uses the Filesystemobject to traverse through all the subdirectories and display them:
    
    
    Sub ShowFolderList(folderspec)
        Dim fs, f, f1, fc, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set fc = f.SubFolders
        For Each f1 in fc
            s = s & f1.name 
            s = s &  vbCrLf
        Next
        MsgBox s
    '####
    I want to copy c:\temp\test.txt file to this found folder
    End Sub

    I would really appreciate if anyone can help. Lot of thanks in advance

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:34 PM Unanswerable drive-by question
    Friday, September 7, 2018 1:27 PM

All replies

  • You are enumerating several, perhaps many, subfolders. Do you want to copy test.txt to all of them?

    Edit: Check out the FileCopy method of the FileSystemObject.

    https://docs.microsoft.com/en-us/previous-versions/tn-archive/ee198744(v%3dtechnet.10)


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)




    Friday, September 7, 2018 1:45 PM
  • Thanks Richard. No only one that is found by the script. The folder I will be copying to, there will be only one folder. I know the file copy method but want to know how can i use it by that "s" value found in the code earlier. thx

    Friday, September 7, 2018 4:42 PM
  • You need to use the Path property of the folder, rather than the Name property. I would suggest:

    fs.CopyFile "c:\temp\test.txt file" , "f1.Path\"


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Friday, September 7, 2018 5:48 PM