473,569 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy file into sub-directories

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!

Aug 12 '05 #1
3 6292
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
Aug 12 '05 #2
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_da rkfalz.com> wrote in message
news:OP******** ******@tk2msftn gp13.phx.gbl...
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

Aug 12 '05 #3
"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
Aug 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
21009
by: DraguVaso | last post by:
Hi, I'm looking for a way to Copy and Paste Files to the clipboard. I found a lot of articles to copy pieces of text and bitmaps etc, but nog whole files. Whay I need is like you have in windows explorer: when you do a right-click on a file and choose Copy, and than paste it somewhere in my application and vice versa.
7
11608
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an...
5
1378
by: Hans Munich | last post by:
Szenario: User selects a XML File ("products.xml") to import newest Data. Data should replace Data in an existing Acess File which is connected via Dataadapter (daadaptFLR). Bevore the Existing Data are deleted with RunSQL("DELETE * From Tbl_Fl_Rundleitung"). Function the Works: If I copy the File from the directory of the...
12
2525
by: samoore33 | last post by:
I found a real nice article on how to copy a directory on MSDN. The only problem is that I can not figure out how to get the namespace Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has had experience with this, or knows of a different way to copy a directory using VB. I found ways to copy files, but not having a lot of...
2
2790
by: TwistedPair | last post by:
All, This is sort of a continuation of a previous post of mine. The code below basically reads a registry key to get a path to a folder and it watches for files created in that folder (only created). It also reads another registry key for another path which is a destination path. When a file shows up, it copies it off. It actually works...
0
1189
by: TwistedPair | last post by:
All, I had some great advice about this a bit ago, but I'm just not good enough with this code to put together all the pieces. The way the code below works is as a service. When it is started, it watches a folder that is set in a registry key, and if there is a file created in that folder, it copies it to a destination folder, also defined...
4
4632
by: TwistedPair | last post by:
All, Been trying to get a little program to work, and I think I'm really close, but I'm afraid I need to be pointed in the right direction. The code below will watch a directory for files created. If a file is created, it will copy it off to another directory. This even works if a bunch of files are created all at once, but after a few...
4
5419
by: taufik | last post by:
hi guys... i new person using vb.net i have some problem in copy a file into specific directory create by user... below is coding that write that may help u all to solve my problem Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code "
6
5068
by: Michael | last post by:
I need to copy a huge file (around 300Mb) from a mapped network drive to another. I have created a console application and used System.IO.File.Copy function. But I want to know the process of this copying work. Is there any way? I am thinking that I can get the file size, but I don't know how to get the size copied. Thanks.
1
1356
by: veer | last post by:
hi it looks a silly question but i m getting confused actually i want to copy folders from one location to another like from C:\abc To D:\xyz here abc and xyz are two folders in c and d drive it works fine when whole folder including sub folders of "abc" are to be copied into "xyz" folder but i have a index file "index.xls" which contain some...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.