Page 1 of 2 12>
Topic Options
#153298 - 2005-12-13 02:48 PM Copy folder script.
JTestman Offline
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 Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
all that copying... why not shell xcopy?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#153300 - 2005-12-13 03:10 PM Re: Copy folder script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
how big is the total size of the copied stuff?
if not big, I say, go and copy for all at once.
maybe add a small sleep between the turns.

if the server is a real server (separate raid cards and stuff) the extra load is no problem for it and users won't see a thing.
_________________________
!

download KiXnet

Top
#153301 - 2005-12-13 03:31 PM Re: Copy folder script.
JTestman Offline
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 Offline
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#153304 - 2005-12-13 03:58 PM Re: Copy folder script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or simply see the manual for dir()
Code:

$=dir("e:\data")
do
$ ?
$=dir()
until $=""

_________________________
!

download KiXnet

Top
#153305 - 2005-12-13 05:56 PM Re: Copy folder script.
JTestman Offline
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
#153306 - 2005-12-13 07:30 PM Re: Copy folder script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh?
why don't you use the same path as in the example code?
actually, you don't even use the path that your example is showing.

please, clarify what are the paths where you want to copy and from where.
_________________________
!

download KiXnet

Top
#153307 - 2005-12-13 08:13 PM Re: Copy folder script.
JTestman Offline
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
#153308 - 2005-12-13 08:19 PM Re: Copy folder script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
next question.
is there subfolders that you need to copy?
if there is, xcopy makes sense but then the current way of listing does not work.

if there is no sub dirs, use kixtart's copy instead.

so, simply:
Code:

copy $sourcedir+'\*.*' 'e:\data\'+$folder+'\data\netscape7\'
copy 'e:\data\'+$folder+'\data\netscape\*.*' 'e:\data\'+$folder+'\data\netscape7\'

_________________________
!

download KiXnet

Top
#153309 - 2005-12-13 10:55 PM Re: Copy folder script.
JTestman Offline
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
#153310 - 2005-12-14 12:10 AM Re: Copy folder script.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Shell takes only a single parm, not 2 parms!
There are several FAQs on the use of shell and quotes.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#153311 - 2005-12-14 04:14 AM Re: Copy folder script.
JTestman Offline
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
#153312 - 2005-12-14 04:52 AM Re: Copy folder script.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What follows the SHELL comand within a matched pair of quotes that is not concatenated with + constitutes one parm. So, following that logic, your attempt goes like this:

KiX command - SHELL
Parm for SHELL - 'cmd /c xcopy e:\data1\'+$folder+'\data\netscape\*.*'
second (unsupported parm - 'e:\data1\'+$folder+'\data\Netscape7\ /d /e /c /y /h /r'

If you concatenated the two parms, it would be legal code:

shell 'cmd /c xcopy e:\data1\'+$folder+'\data\netscape\*.* ' + 'e:\data1\'+$folder+'\data\Netscape7\ /d /e /c /y /h /r'

The FAQs are:
Not quite everything you wanted to know about RUN and SHELL
Proper use of quotes
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#153313 - 2005-12-14 04:57 AM Re: Copy folder script.
NTDOC Administrator Offline
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
#153314 - 2005-12-14 05:10 AM Re: Copy folder script.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
hmmm... mismatched quotes there DOC.
edit: K, well, there were before he edited and covered his tracks.


Edited by Les (2005-12-14 02:54 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#153315 - 2005-12-14 06:37 AM Re: Copy folder script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
heh.
_________________________
!

download KiXnet

Top
#153316 - 2005-12-14 07:12 AM Re: Copy folder script.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
ROFLMAO - That sure saves on tapes


Doesn't do much for your restores though.
 

Top
#153317 - 2005-12-14 07:23 AM Re: Copy folder script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
doc seems to be commenting on my sig...
need to clear it out so nobody else will get confused.
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 918 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.077 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org