Jump to content

Script to copy files to student home directory.


Recommended Posts

Posted

Has anyone written a script that has the following:

1. Ability to browse or change in code, the location of some files, eg d:\files-to-copy

2. Read all the users in a specific OU (eg, 'Year 10'), extract their home directory from active directory

3. Copy all the files from (1) to (2) in sequence?

 

Ive written a lame way of doing it in a batch file but its just not reliable so I need it to read through all the Users in an OU and grab their home directory that way.

 

Thanks

Posted

Thats a good idea, but I think ill run into a similar problem that Im currently getting.

One of the files is a Database which seems to get screwed up when multiple people start copying at the same time (im guessing it gets locked while a few people are copying it across to their area).

 

When its done copying across some people can open it normally and others get 'this database is read only bla bla bla' File permissions are fine for the student after copying and file is not set to read only.

 

On top of that, for exam use, id like to have it done and working before the minute the exam starts to find out its not worked.

Posted
1. Ability to browse or change in code, the location of some files, eg d:\files-to-copy

 

Not sure what you are asking here please clarify.

 

As for the rest.. do you not sort the home directories into year groups eg users\students\year11\. If that is the case you wouldnt need to dive into ad to get the home directories, you already know where they all are and a script could copy whatever into each folder.

Posted
Just had another thought.. if your only problem with your current script is that some files are copied over as read only, maybe what you could do is to change the attrib ie in dos its attrib -r filename.ext.
Posted

The permissions/attributes arent a problem, after the file is copied across, the student has full control of the file and the file is not read only, there are no deny permissions. They still get the message that the database is read only.

 

Students folders are arranged as intake years (since year 7 turns into year 8 etc), eg d:\users\2001intake (current year 11).

 

Not too sure how to get a batch file to loop round all folders inside the intake folder to copy the files though.

 

PS I was using 'copy' and have switched to 'xcopy', ive yet to see if this makes a difference

Posted

I hope robocopy is useful to you but if you still want to know how to loop through the subdirectories.. heres how you would do it in vbs:

 

Dim oFS, oFolder, WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
Set oFolder = oFS.GetFolder("c:\browse")


ShowFolderDetails oFolder

Sub ShowFolderDetails(oF)
Dim F
for each F in oF.subfolders
	wshshell.run "c:\windows\system32\xcopy.exe c:\copy\*.* """ & F & "\my documents\"""
next
End Sub

 

The script above will go through each subdirectory in c:\browse and then run the xcopy command to copy all files out of c:\copy to the my documents folder in each subdirectory. Change it to suit.

  • Thanks 1
Posted

Thanks.

 

Can you modify that slightly so that it will copy them in sequence, ie

copy files -> folder 1 copy files -> folder 2

instead of opening multiple instances of xcopy at the same time?

 

Just incase I run into the same problem of the database being copied at the same time and locking.

Posted

wshshell.run "c:\windows\system32\xcopy.exe c:\copy\*.* """ & F & "\my documents\"""

 

Just replace the above code with:

 

wshshell.run "c:\windows\system32\xcopy.exe c:\copy\*.* """ & F & "\my documents\""",,True

 

The additional arguments should tell it to wait untill program terminates. I havent tested it so check it out first be for you run it on your server.

Posted
NP. VB scripting is useful but i do find myself manipulating other people's code or one i have in a store to suit more than creating it all from scratch. It think its because I dont get to do much scripting that each time i do i need to remind myself of everthing like the libraries, classes.. etc
Posted
I really need to read up on vbs scripting, living in the dark ages using batch files!

 

VBScript has its uses but I wouldn't go out of my way to learn it. MS have ditched it VBScript. I'd recommend Python as a (beginner) scripting language - it's much more powerful than VBScript. MS have recognised this as they are about to embrace and extinguish python in the form of 'ironpython'.

Posted
VBScript has its uses but I wouldn't go out of my way to learn it. MS have ditched it VBScript. I'd recommend Python as a (beginner) scripting language - it's much more powerful than VBScript. MS have recognised this as they are about to embrace and extinguish python in the form of 'ironpython'.

 

Hello ?? Where did you get that from. Microsoft have not ditched VBS. Visual Basic 6 has been ditched in favour of VB.net but these are compiled languages not script interpreters.

 

Yes, before someone says it, there is the new MONAD scripting enviroment on the horizon but it will debut on Exchange 12 and then on the Black Comb server. Perhpas there will be a standalone install for 2003 Server and XP. The main thing is VBS will be with us for sometime.

 

Before then you could also try KiXtart which is a very popular VBS alternative. It has been customised for system administration so avoid some of the more cumbersome constructions found necessary with VBS.

Posted

I wasn't saying it was completely useless, just that if someone was about to embark on leaning a new language then there are better options than VBScript.

python/perl/js/php have a brighter future.

VBScript will indeed be with us for some time, but so will many outdated things.

Things move on, VBscript won't.

Posted

@Geoff and CybNerd

 

Your advocacy of FLOSS is commendable and in an ideal world it would be nice to have Python or C/Z/BA/SH installed by default on everybodys favourite monoply OS but if you admin a Windows network then knowledge of VBS is probably more useful.

 

Out of interest does anybody here run Python login scripts?

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...