Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving to multiple users folders 1

Status
Not open for further replies.

itsfisko

Technical User
Jan 19, 2002
226
GB
is it possible to have a script save a document to all the home directories of a network?
I post this here as apprently i posted this question in the wrong place.
Thanks for any help ,school tech :)

Some lead, some follow....I just Hope!
 
Hello itsfisko,

Unless you hide some crucial given behind the question, I do not see any difficulty in saving a document to a multiple of places. Just save the document one-by-one to the target folders?

regards - tsuji
 
hi perhaps i did not make my question clear I wish to save to multiple users folder with a script with one operation

Some lead, some follow....I just Hope!
 
Yes, you an do this. You will want to enumerate all of the sub folders within your user share. Then use a For/next statement to walk through each folder and do the save.

[script]
Dim fso
Dim path
Dim oFolder
Dim oSubFolder

Set fso = createobject("Scripting.FileSystemObject")
Path = "E:\Users"
Set oFolder = fso.GetFolder(Path)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
code to save your file

Next

[/script]

As an alternative if you don't want the file to go to EVERY subfolder, you could provide a list of folder and read that list into an array. refer to my FAQ faq329-4871 for an example.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
itsfisko,

Except that mov ah,02 or alike that I can think of is remotely ressemble to "one operation", one operation means a lot of operation hidden. Making more operations above the surface does not make the construction less respectible, sometimes, the contrary.

- tsuji
 
Hi Mark,
I have looked at your script and I can see where to change it to allow me to save to the users folders which are:
\\server2k1\01001,\\server2k1\01002,\\server2k1\01003 etc etc or I could use D:\users to save to all the users. However I canot see where I put the path to the document that I whish to save to the users.
Thanks stressed school tech

Some lead, some follow....I just Hope!
 
Provide some more details on where the document exists now and I will give you sample code.

You would put the code where I indicated "code to save your file"

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
thanks Mark the document wil be in my docs on the server so it would be in \\server2k1\FISK\my documents thanks for your help :)

Some lead, some follow....I just Hope!
 
Here you go this shoudl do the trick. You will need to edit the doc name and just verify the local path to the file.

Code:
Dim fso 
Dim path
Dim oFolder
Dim oSubFolder
Const OverwriteExisting = True

Set fso = createobject("Scripting.FileSystemObject")
Doc = "E:\FISK\DocumentName.doc"
Path = "E:\Users"
Set oFolder = fso.GetFolder(Path)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
	fso.CopyFile Doc , path & "\" & oSubFolder.Name & "\", OverwriteExisting    
Next


I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hi Mark thanks for you coding help the script works fine, I am trying to tune it to allow me to write to sets of users ( A year group) the users all have a number that identifies the year they started in school ie 04; then the number runs from 1 to 150 so that I have a list of user names that are 04001 04002 04003 etc etc. I am trying now to see if I can put this into your script. The final refinement will be to have an input box for the scource file and an input box for the string of user names.
If you have any thought on this.....
Thanks once again John stressed school tech in eastern England. ;-)

Some lead, some follow....I just Hope!
 
Replace this line:
Code:
Doc = "E:\FISK\DocumentName.doc"

With this:
Code:
FileName = InputBox("Enter the file name including extension","What File?")
Doc = "E:\FISK\" & FileName
YearPrompt = InputBox("Enter 2 Digit Year to Copy File To","What Year?")


Then replace this section:
Code:
For Each oSubfolder in colSubfolders
    fso.CopyFile Doc , path & "\" & oSubFolder.Name & "\", OverwriteExisting    
Next
With this:
Code:
For Each oSubfolder in colSubfolders
  If Left(oSubFolder.Name, 2) = YearPrompt Then
    fso.CopyFile Doc , path & "\" & oSubFolder.Name & "\", OverwriteExisting    
  End If
Next


I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Mark you are just the best!
This little code will solve and save me loads of time and stress.
Thanks once again, John ;-)

Some lead, some follow....I just Hope!
 
Hi Mark in a final amendment I have changed the scource to allow the code to pic a file from a folder called OUTBOX the next trick is to get it to go into a folder called INBOX in the target users folders. Thanks once again John Slightly less stressed school tech. ;-)

Some lead, some follow....I just Hope!
 
fso.CopyFile Doc , path & "\" & oSubFolder.Name & "\Outbox\" , OverwriteExisting



I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hi Mark i Tried yor suggestion to set it to copy to a specific folder, for some reason it will not work my code so far is:

Dim fso
Dim path
Dim oFolder
Dim oSubFolder
Const OverwriteExisting = True

Set fso = createobject("Scripting.FileSystemObject")

FileName = InputBox("Enter the file name including extension","What File?")
Doc = "\\server2k1\staff\FISK\OUTBOX\" & FileName
YearPrompt = InputBox("Enter 2 Digit Year to Copy File To","What Year?")

Path = "\\server2k1\pupils"
Set oFolder = fso.GetFolder(Path)
Set colSubfolders=oFolder.Subfolders

For Each oSubfolder in colSubfolders
If Left(oSubfolder.name, 2) = YearPrompt Then

fso.CopyFile Doc , path & "\" & oSubFolder.Name & "\" , OverwriteExisting

End If
Next
******************************

perhaps a prompt for which remote folder to save to would make the save to the remote folder easier, I willtry to figure this out, thanks John semi stressed school tech ;-)


Some lead, some follow....I just Hope!
 
Looks like that is my bad...

Use this line for the copy instead.

fso.CopyFile Doc , path & "\" & oSubFolder.Name & "\", True

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hi mark thanks for your help, however the script will place a document in the users MY DOCUMENTS folder but I cannot seem to get it to place it into a specific target folder within that, ie: an INBOX it is very close so it can only be a matter of a small tweak and it will be perfect
Thanks once again John chilled out school tech ;-)

Some lead, some follow....I just Hope!
 
So does the below work? If not what happens?

I should have referred back to my original code above. My last post can be ignored, I was setting the OverwriteExisting to True.

fso.CopyFile Doc , path & "\" & oSubFolder.Name & "\Inbox\", OverwriteExisting

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hi Mark it fail im afraid with error file not found
code:800A004C line 20 char 1
John :) thanks again

Some lead, some follow....I just Hope!
 
OK, so that is indicating that it is not finding the file name you are specifying in the inputbox. Are you giving the full path to the file?

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top