Copy file into sub-directories

Discussion in 'ASP General' started by Jake, Aug 12, 2005.

  1. Jake

    Jake Guest

    I know how to copy files from one location to another but how would I go
    about copying a file from one directory into serveral - or actually all
    subdirectories in a single action? Some kind of loop?

    Basically I want to be able to enter a filename into a text field and click
    submit which would then copy the named file (which resides in the root
    directory) into every subdirectory under the root (1 level only). Would be
    helpful to be able to specify mutliple files to be copied at once.

    Any suggestions or code samples greatly appreciated!
    Jake, Aug 12, 2005
    #1
    1. Advertising

  2. Jake

    Curt_C [MVP] Guest

    Jake wrote:
    > I know how to copy files from one location to another but how would I go
    > about copying a file from one directory into serveral - or actually all
    > subdirectories in a single action? Some kind of loop?
    >
    > Basically I want to be able to enter a filename into a text field and click
    > submit which would then copy the named file (which resides in the root
    > directory) into every subdirectory under the root (1 level only). Would be
    > helpful to be able to specify mutliple files to be copied at once.
    >
    > Any suggestions or code samples greatly appreciated!
    >
    >
    >

    a loop as you suspect.
    you'll have to have a list of the folders, or gather them from another
    looping with FSO, then copy it into them one at a time.

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
    Curt_C [MVP], Aug 12, 2005
    #2
    1. Advertising

  3. Jake

    Jake Guest

    Wow - above my head!
    How would I go about getting the list of folders with FSO? The folders will
    be in the hundreds and their names will change frequently so I wont ever
    have a up to date list.

    Thanks!




    "Curt_C [MVP]" <software_at_darkfalz.com> wrote in message
    news:...
    > Jake wrote:
    >> I know how to copy files from one location to another but how would I go
    >> about copying a file from one directory into serveral - or actually all
    >> subdirectories in a single action? Some kind of loop?
    >>
    >> Basically I want to be able to enter a filename into a text field and
    >> click submit which would then copy the named file (which resides in the
    >> root directory) into every subdirectory under the root (1 level only).
    >> Would be helpful to be able to specify mutliple files to be copied at
    >> once.
    >>
    >> Any suggestions or code samples greatly appreciated!
    >>
    >>
    >>

    > a loop as you suspect.
    > you'll have to have a list of the folders, or gather them from another
    > looping with FSO, then copy it into them one at a time.
    >
    > --
    > Curt Christianson
    > site: http://www.darkfalz.com
    > blog: http://blog.darkfalz.com
    Jake, Aug 12, 2005
    #3
  4. Jake

    McKirahan Guest

    "Jake" <> wrote in message
    news:urO$...
    > I know how to copy files from one location to another but how would I go
    > about copying a file from one directory into serveral - or actually all
    > subdirectories in a single action? Some kind of loop?
    >
    > Basically I want to be able to enter a filename into a text field and

    click
    > submit which would then copy the named file (which resides in the root
    > directory) into every subdirectory under the root (1 level only). Would be
    > helpful to be able to specify mutliple files to be copied at once.
    >
    > Any suggestions or code samples greatly appreciated!


    This doesn't sound like it requires an ASP solution.

    Perhaps just a VBScript program would do it.

    '*
    '* This VBScript program copies one or more files into
    '* each subfolder under the folder containing this script.
    '*
    '* Using Windows Explorer, drag-and-drop files onto this script.
    '*
    Option Explicit
    '*
    '* Declare Constants
    '*
    Const cVBS = "filecopy.vbs"
    '*
    '* Declare Variables
    '*
    Dim intARG
    Dim strARG
    strARG = "Filename(s): "
    Dim strFIL
    Dim strFOL
    Dim booGSF
    booGSF = True
    Dim intGSF
    intGSF = 0
    Dim strGSF
    Dim strSFN
    strSFN = WScript.ScriptFullName
    strSFN = Left(strSFN,InStrRev(strSFN,"\"))
    '*
    '* Declare Objects
    '*
    Dim objARG
    Set objARG = WScript.Arguments
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objGFO
    Set objGFO = objFSO.GetFolder(strSFN)
    Dim objGSF
    Set objGSF = objGFO.SubFolders
    '*
    '* Process Each File
    '*
    For intARG = 0 To WScript.Arguments.Count - 1
    strFIL = objARG.Item(intARG)
    strARG = strARG & vbCrLf & vbTab & strFIL
    '*
    '* Process Each Subfolder
    '*
    For Each strGSF in objGSF
    If booGSF Then intGSF = intGSF + 1
    strFOL = strSFN & strGSF.Name & "\"
    objFSO.CopyFile strFIL, strFOL, True
    Next
    booGSF = False
    Next
    '*
    '* Destroy Objects
    '*
    Set objGSF = Nothing
    Set objGFO = Nothing
    Set objFSO = Nothing
    Set objARG = Nothing
    '*
    '* Finish
    '*
    strARG = strARG & vbCrLf & "copied into " & intGSF & " subfolders."
    MsgBox strARG,vbInformation,cVBS
    McKirahan, Aug 12, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Finkel
    Replies:
    0
    Views:
    491
    Joel Finkel
    Sep 12, 2003
  2. Ben
    Replies:
    2
    Views:
    883
  3. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,020
    Lawrence D'Oliveiro
    May 20, 2011
  4. Ron Smith
    Replies:
    5
    Views:
    146
    Michele Dondi
    Nov 2, 2004
  5. Replies:
    17
    Views:
    93
    Rustom Mody
    May 22, 2014
Loading...

Share This Page