#153298 - 2005-12-13 02:48 PM
Copy folder script.
|
JTestman
Fresh Scripter
Registered: 2005-11-28
Posts: 26
|
Hello –
I have a login script that builds a folder structure and copies data into it, my project took a turn and we decided not to wait for users to login. So now I need to modify or rebuild this login script to a script that I can run on the server against a drive containing home folders, roughly 2k of them.
Sense this is going to be running against a server I want to try and not overwhelm it by having mass copying. I would like to reference a list of directories to run against that I can populate. Maybe something like Directory.txt = h:\data\User1,h:\data\User2,h:\data\User3,h:\data\User4
So being new to this I guess a loop that will somehow reference the directory file and change the folder name part of the path? Can someone please help me get this started? My login script is below.
Code:
;************************************************************************* ; Script Name: Netscape 4.7 to 7.1 Migration "net7mig.kix" ; Author: JTestman, UDF Error Functions Jooel Nieminen ; Date: 12/5/2005 ; Requirements: Tested with kix 4.51 ; Description: Based on AD group membership, Migrates 4.7 data to 7.1, ; creates 7.1 directory structures, copies 7.1 source data ; into 7.1 then moves 4.7 data into new dir structure, ; deletes 7.1 bookmarks and renames 4.7 bookmarks to 7.1. ; Renames %userprofile%\appdata\mozzila\registry.dat, ; then copies hard coded registry.dat from source directory. ;*************************************************************************
break on dim $file, $fileversion, $47data1, $47data2, $file, $readini dim $71data1, $71data2, $71data3, $SourceMozzila, $iniFileSource dim $iniFileDeployed, $Sourcedata711, $Sourcedata712, $Sourcedata713
;Working Paths $47data1 = 'c:\Data\Netscape' $47data2 = 'c:\Data\Netscape\Cache' $71data1 = 'c:\Data\Netscape7\Default User\userdata.slt' $71data2 = 'c:\Data\Netscape7\Default User\userdata.slt\Cache' $71data3 = 'c:\Data\Netscape7\Default User\userdata.slt\chrome' $SourceMozzila = 'c:\Data\Source\Mozzila' $Sourcedata711 = 'c:\Data\Source\Mozzila\Netscape7' $Sourcedata712 = 'c:\Data\Source\Mozzila\Netscape7\Cache' $Sourcedata713 = 'c:\Data\Source\Mozzila\Netscape7\chrome' $Registry = '%userprofile%\Application Data\Mozilla\Registry.dat' $file = '%userprofile%\Application Data\Mozilla' $iniFileSource = 'c:\Data\Source\Mozzila\migration.ini' $iniFileDeployed = '%userprofile%\Application Data\Mozilla\migration.ini' $FileExistLog = 'c:\Data\Source\logs' $ErrorFile = 'c:\Data\Source\logs\Errors.log'
;Check AD for group membership ;IF INGROUP('group')
;Check to see if migration.ini is present and value =True - ;if it is Exit script
$readini = ReadProfileString($iniFileDeployed, 'NetscapeMigration', 'Migrated71') If $readini = True LogErrors()
;Write log for file exsiting RedirectOutput('$FileExistLog\%username%71Exist.txt',1) ?'Last login by '@USERID ?'NetBIOS name = '@WKSTA ?'This information was gathered on '@DATE' at '@TIME LogErrors()
;Exit script EXIT 1
;If the value isn't present in the migration.ini Do stuff Else
;Make Netscape7 dir MD $71data1 LogErrors() MD $71data2 LogErrors() MD $71data3 LogErrors()
;Copy 7.1 source files from share to user 7.1 directories ;Delete 7.1 bookmarks copy '$Sourcedata711\*.*' '$71data1\*.*' LogErrors() copy '$Sourcedata712\*.*' '$71data2\*.*' LogErrors() copy '$Sourcedata713\*.*' '$71data3\*.*' LogErrors() del '$71data1\bookmarks.html' LogErrors()
; copy netscape 4.7 data to 7.1 copy '$47data1\*.*' '$71data1\*.*' LogErrors() copy '$47data1\Cache\*.*' '$71data1\Cache\*.*' LogErrors()
;Rename bookmarks file move '$71data1\bookmark.htm' '$71data1\bookmarks.html' LogErrors()
;Rename %userprofile%\Application Data\Mozilla\registry.dat move '$file\registry.dat' '$file\registry.old' LogErrors()
;Copy registry.dat from network share copy '$SourceMozzila\registry.dat' '$file\registry.dat' LogErrors()
;Create ini file to %username%\application data\mozilla\ writeprofilestring($iniFileDeployed, 'NetscapeMigration', 'Migrated71', 'True') LogErrors()
;Write log Successful RedirectOutput('$FileExistLog\%username%Migrated71.txt',1) ?'Last login by '@USERID ?'NetBIOS name = '@WKSTA ?'This information was gathered on '@DATE' at '@TIME LogErrors()
;EndIF EndIF
;Error logging function, UDFfunction LogErrors()
function LogErrors() if @error $errorString = @userid + "--> " + @serror + " (" + @error + ")" $=RedirectOutput($ErrorFile) $errorString ? $=RedirectOutput($) endif endfunction
|
|
Top
|
|
|
|
#153299 - 2005-12-13 03:07 PM
Re: Copy folder script.
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
all that copying... why not shell xcopy?
|
|
Top
|
|
|
|
#153301 - 2005-12-13 03:31 PM
Re: Copy folder script.
|
JTestman
Fresh Scripter
Registered: 2005-11-28
Posts: 26
|
It’s around 2Mb per account and 2k accounts between creating directories and moving/copying files around.
I like your sleep idea the server isn’t adequate for the load, I'm migrating the data to a new Active/Active cluster. But this Netscape hell is a higher priority as the server is stable and we aren’t adding additional accounts.
|
|
Top
|
|
|
|
#153302 - 2005-12-13 03:38 PM
Re: Copy folder script.
|
JTestman
Fresh Scripter
Registered: 2005-11-28
Posts: 26
|
Is there a way to programmatically run this against every folder without knowing the folders name?
The directory structures are the same for all folders it’s just the folder name. Example:
E:\data\ADoe\data\Netscape E:\data\BDoe\data\Netscape E:\data\CDoe\data\Netscape E:\data\DDoe\data\Netscape E:\data\EDoe\data\Netscape
|
|
Top
|
|
|
|
#153303 - 2005-12-13 03:51 PM
Re: Copy folder script.
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
see folderlist() UDF
for each $folder in folderlist('e:\data') shell 'cmd /c xcopy '+$sourcedir+' e:\data\'+$folder+'\data\netscape /d /e /c /y /h /r' next
|
|
Top
|
|
|
|
#153305 - 2005-12-13 05:56 PM
Re: Copy folder script.
|
JTestman
Fresh Scripter
Registered: 2005-11-28
Posts: 26
|
*Edited to clean up paths 12/13/05 13:45*
I really like this example.
Question?
I know line 6 in the code below is incorrect how do I copy files and sub folders from within a folder to another folder for the same username with out knowing the user name? your example looks like it only copy’s the source folder to all folders.
Code example below.
Example: Copy: e:\source\netscape7\*.* to e:\%username%\data\netscape7\ Copy: e:\data\%username%\netscape\*.* to e:\data\%username%\data\netscape7\
Also is this an up to data version of the Folder UDF? I searched around for this UDF and this is the only reference I found.
Code:
$sourcedir = "e:\source\netscape7"
for each $folder in folderlist('e:\data') shell 'cmd /c xcopy '+$sourcedir+' e:\data\'+$folder+'\data\netscape /d /e /c /y /h /r'
Shell 'cmd /c xcopy '+$folder+\data\' '+$folder+'\data\netscape7\default user\usedata.slt /d /e /c /y /h /r'
next
; UDF Function FolderList
Function FolderList($folderName,optional $mask) dim $objDir, $objFld, $objFile, $t, $name $objDir = CreateObject('Scripting.FileSystemObject') if @error Exit 1 Endif $objFld = $objDir.GetFolder($folderName).SubFolders if @error exit 2 endif ; usually folder not found For Each $objFile In $objFld $name=$objFile.name if ($mask and instr($name,$mask)) or not $mask $t=$t+'|'+$name endif Next $FolderList=split(substr($t,2),'|') $objDir = 0 EndFunction
Edited by JTestman (2005-12-13 07:48 PM)
|
|
Top
|
|
|
|
#153307 - 2005-12-13 08:13 PM
Re: Copy folder script.
|
JTestman
Fresh Scripter
Registered: 2005-11-28
Posts: 26
|
Sorry about that..
Hope this makes sense, for each user I need to copy the Netscape7 source files and into a Netscape7 directory and then copy each users original Netscape data into their new Netscape7 folder because it contains their bookmarks and SSL certificates.
Copy Netscape7 source files to each users (e:\data\%username%\data\Netscape7\) folder. Example: Copy e:\source\netscape7\*.* To e:\data\%username%\data\netscape7\
Copy/overwrite the users Netscape7 data with their Netscape data. Example: Copy e:\data\%username%\data\netscape\*.* To e:\data\%username%\data\netscape7\
Code:
$sourcedir = "e:\source\netscape7"
for each $folder in folderlist('e:\data')
; Shell statements, DO Stuff
shell 'cmd /c xcopy '+$sourcedir+' e:\data\'+$folder+'\data /d /e /c /y /h /r' shell 'cmd /c xcopy '+$folder+' e:\data\netscape'+$folder+'\data\ /d /e /c /y /h /r'
next
; UDF Function FolderList
Function FolderList($folderName,optional $mask) dim $objDir, $objFld, $objFile, $t, $name $objDir = CreateObject('Scripting.FileSystemObject') if @error Exit 1 Endif $objFld = $objDir.GetFolder($folderName).SubFolders if @error exit 2 endif ; usually folder not found For Each $objFile In $objFld $name=$objFile.name if ($mask and instr($name,$mask)) or not $mask $t=$t+'|'+$name endif Next $FolderList=split(substr($t,2),'|') $objDir = 0 EndFunction
|
|
Top
|
|
|
|
#153309 - 2005-12-13 10:55 PM
Re: Copy folder script.
|
JTestman
Fresh Scripter
Registered: 2005-11-28
Posts: 26
|
What do you mean by? Quote:
if there is, xcopy makes sense but then the current way of listing does not work.
I have sub directories I need to copy.
I'm having trouble with this shell statement, it asks me if I want to overwrite the file and then nothing happens.
Code:
shell 'cmd /c xcopy e:\data1\'+$folder+'\data\netscape\*.*' 'e:\data1\'+$folder+'\data\Netscape7\ /d /e /c /y /h /r'
|
|
Top
|
|
|
|
#153311 - 2005-12-14 04:14 AM
Re: Copy folder script.
|
JTestman
Fresh Scripter
Registered: 2005-11-28
Posts: 26
|
I didn’t know how to get the flags to work wit the copy command.
I'm able to accomplish what I need without the shell but just out of curiosity how would it work with only a single parameter? I searched and didn’t see any topics referencing shell and parameter usage.
Code:
for each $folder in folderlist('c:\data1')
copy 'c:\data1\'+$folder+'\data\netscape\*.*' 'c:\data1\'+$folder+'\data\netscape7\' /s /c /r
next
; UDF Function FolderList
Function FolderList($folderName,optional $mask) dim $objDir, $objFld, $objFile, $t, $name $objDir = CreateObject('Scripting.FileSystemObject') if @error Exit 1 Endif $objFld = $objDir.GetFolder($folderName).SubFolders if @error exit 2 endif ; usually folder not found For Each $objFile In $objFld $name=$objFile.name if ($mask and instr($name,$mask)) or not $mask $t=$t+'|'+$name endif Next $FolderList=split(substr($t,2),'|') $objDir = 0 EndFunction
|
|
Top
|
|
|
|
#153313 - 2005-12-14 04:57 AM
Re: Copy folder script.
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
meaning that you have supplied to parameters to cmd which won't work. You did this by isolating with single quotes for each parameter. Also since XCOPY is an executable of it's own you may not need CMD.EXE to run it.
Not tested but something like this
Code:
'xcopy "e:\data1\"+$folder+"\data\netscape\*.* e:\data1\"+$folder+"\data\Netscape7\ /d /e /c /y /h /r"'
|
|
Top
|
|
|
|
#153316 - 2005-12-14 07:12 AM
Re: Copy folder script.
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
ROFLMAO - That sure saves on tapes
Doesn't do much for your restores though.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 778 anonymous users online.
|
|
|