Copy file into sub-directories

J

Jake

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!
 
C

Curt_C [MVP]

Jake said:
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.
 
J

Jake

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!
 
M

McKirahan

Jake said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top