"Jake" <sp******@allte l.net> wrote in message
news:ur******** ******@tk2msftn gp13.phx.gbl...
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.v bs"
'*
'* 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.ScriptF ullName
strSFN = Left(strSFN,InS trRev(strSFN,"\ "))
'*
'* Declare Objects
'*
Dim objARG
Set objARG = WScript.Argumen ts
Dim objFSO
Set objFSO = CreateObject("S cripting.FileSy stemObject")
Dim objGFO
Set objGFO = objFSO.GetFolde r(strSFN)
Dim objGSF
Set objGSF = objGFO.SubFolde rs
'*
'* Process Each File
'*
For intARG = 0 To WScript.Argumen ts.Count - 1
strFIL = objARG.Item(int ARG)
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,vbInform ation,cVBS