#145191 - 2005-08-10 04:03 AM
Need a Script Check
|
StarwarsKid
Seasoned Scripter
   
Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
|
Hi everyone, Could you look my new script over and tell me if there is a more efficient way of performing the scripted tasks?
Code:
if ingroup ("GISSHAPES") $Result = CompareFileTimes("I:\gisdata\shape\DONOTDELETE-GISscript.txt", "C:\gisdata\shape\DONOTDELETE-GISscript.txt") IF $Result = 1 ; '1'=File1 is more recent than file2 COPY "i:\gisdata\shape\DONOTDELETE-GISscript.txt" "c:\gisdata\shape\DONOTDELETE-GISscript.txt" COPY "i:\gisdata\shape\airport\" "c:\gisdata\shape\airport\" COPY "i:\gisdata\shape\bldgs\" "c:\gisdata\shape\bldgs\" COPY "i:\gisdata\shape\bmarks\" "c:\gisdata\shape\bmarks\" COPY "i:\gisdata\shape\cbs\" "c:\gisdata\shape\cbs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\ease\" "c:\gisdata\shape\ease\" COPY "i:\gisdata\shape\fldplain\" "c:\gisdata\shape\fldplain\" COPY "i:\gisdata\shape\grids\" "c:\gisdata\shape\grids\" COPY "i:\gisdata\shape\inch50\" "c:\gisdata\shape\inch50\" COPY "i:\gisdata\shape\intersec\" "c:\gisdata\shape\intersec\" COPY "i:\gisdata\shape\laterals\" "c:\gisdata\shape\laterals\" COPY "i:\gisdata\shape\limits\" "c:\gisdata\shape\limits\" COPY "i:\gisdata\shape\plats\" "c:\gisdata\shape\plats\" COPY "i:\gisdata\shape\presslns\" "c:\gisdata\shape\presslns\" COPY "i:\gisdata\shape\ss\" "c:\gisdata\shape\ss\" COPY "i:\gisdata\shape\ssstr\" "c:\gisdata\shape\ssstr\" COPY "i:\gisdata\shape\streams\" "c:\gisdata\shape\streams\" COPY "i:\gisdata\shape\streetcl\" "c:\gisdata\shape\streetcl\" COPY "i:\gisdata\shape\streets\" "c:\gisdata\shape\streets\" COPY "i:\gisdata\shape\surveys\" "c:\gisdata\shape\surveys\" COPY "i:\gisdata\shape\tlots\" "c:\gisdata\shape\tlots\" ELSE $Result = -3 ; '-3'=File2 couldn't be open (nonexistant) MD "c:\gisdata\" MD "c:\gisdata\shape\" MD "c:\gisdata\shape\airport\" MD "c:\gisdata\shape\bldgs\" MD "c:\gisdata\shape\bmarks\" MD "c:\gisdata\shape\cbs\" MD "c:\gisdata\shape\dwgs\" MD "c:\gisdata\shape\dwgs\" MD "c:\gisdata\shape\dwgs\" MD "c:\gisdata\shape\ease\" MD "c:\gisdata\shape\fldplain\" MD "c:\gisdata\shape\grids\" MD "c:\gisdata\shape\inch50\" MD "c:\gisdata\shape\intersec\" MD "c:\gisdata\shape\laterals\" MD "c:\gisdata\shape\limits\" MD "c:\gisdata\shape\plats\" MD "c:\gisdata\shape\presslns\" MD "c:\gisdata\shape\ss\" MD "c:\gisdata\shape\ssstr\" MD "c:\gisdata\shape\streams\" MD "c:\gisdata\shape\streetcl\" MD "c:\gisdata\shape\streets\" MD "c:\gisdata\shape\surveys\" MD "c:\gisdata\shape\tlots\" COPY "i:\gisdata\shape\DONOTDELETE-GISscript.txt" "c:\gisdata\shape\DONOTDELETE-GISscript.txt" COPY "i:\gisdata\shape\airport\" "c:\gisdata\shape\airport\" COPY "i:\gisdata\shape\bldgs\" "c:\gisdata\shape\bldgs\" COPY "i:\gisdata\shape\bmarks\" "c:\gisdata\shape\bmarks\" COPY "i:\gisdata\shape\cbs\" "c:\gisdata\shape\cbs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\ease\" "c:\gisdata\shape\ease\" COPY "i:\gisdata\shape\fldplain\" "c:\gisdata\shape\fldplain\" COPY "i:\gisdata\shape\grids\" "c:\gisdata\shape\grids\" COPY "i:\gisdata\shape\inch50\" "c:\gisdata\shape\inch50\" COPY "i:\gisdata\shape\intersec\" "c:\gisdata\shape\intersec\" COPY "i:\gisdata\shape\laterals\" "c:\gisdata\shape\laterals\" COPY "i:\gisdata\shape\limits\" "c:\gisdata\shape\limits\" COPY "i:\gisdata\shape\plats\" "c:\gisdata\shape\plats\" COPY "i:\gisdata\shape\presslns\" "c:\gisdata\shape\presslns\" COPY "i:\gisdata\shape\ss\" "c:\gisdata\shape\ss\" COPY "i:\gisdata\shape\ssstr\" "c:\gisdata\shape\ssstr\" COPY "i:\gisdata\shape\streams\" "c:\gisdata\shape\streams\" COPY "i:\gisdata\shape\streetcl\" "c:\gisdata\shape\streetcl\" COPY "i:\gisdata\shape\streets\" "c:\gisdata\shape\streets\" COPY "i:\gisdata\shape\surveys\" "c:\gisdata\shape\surveys\" COPY "i:\gisdata\shape\tlots\" "c:\gisdata\shape\tlots\" ENDIF ENDIF exit
The script is tested and works just fine, but it is awful long and I'm not sure if I have superfluous commands.
Notes: 1. This is a script I'm writing to automate a manual file copying process one of my GIS engineers has been doing for years. 2. I do need to idenfity each folder seperately as the root folder "i:\gisdata\shapes\" contains other various folders that our GIS engineer doesn't need copied. 3. The "DONOTDELETE-GISscript.txt" files is my way of giving control to the GIS engineer over when the specified folders are copied. My plan was, when he wants to distribute updated folder information he will just edit the text file and the next time the GISSHAPES users login, his changes will be copied.
Thank you, Thank you!
|
|
Top
|
|
|
|
#145194 - 2005-08-10 07:43 AM
Re: Need a Script Check
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
arrays are... well, arrays of data. array has fields/elemenents and each field has a value. so, basically, an array is multiple variables in one. instead of having zillion variable names, you can reference the values from one variable name by the index number.
when you deal with dynamic data that is a must... and in this case too. so, instead of having a line for each subdir, you just put them in simple array: $subdirs = "subdir1","subdir2"
now, as I'm not a perfect teacher... let me see if I can write your script for you 
but before that, I must say you are repeating a lot in your script, like: Code:
COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\"
by just removing dublicates and totally meaningless lines in your script it reduces to: Code:
if ingroup ("GISSHAPES") $Result = CompareFileTimes("I:\gisdata\shape\DONOTDELETE-GISscript.txt", "C:\gisdata\shape\DONOTDELETE-GISscript.txt") IF $Result <> 1 ; '1'=File1 is more recent than file2 $Result = -3 ; '-3'=File2 couldn't be open (nonexistant) ENDIF ENDIF
COPY "i:\gisdata\shape\DONOTDELETE-GISscript.txt" "c:\gisdata\shape\DONOTDELETE-GISscript.txt" COPY "i:\gisdata\shape\airport\" "c:\gisdata\shape\airport\" COPY "i:\gisdata\shape\bldgs\" "c:\gisdata\shape\bldgs\" COPY "i:\gisdata\shape\bmarks\" "c:\gisdata\shape\bmarks\" COPY "i:\gisdata\shape\cbs\" "c:\gisdata\shape\cbs\" COPY "i:\gisdata\shape\dwgs\" "c:\gisdata\shape\dwgs\" COPY "i:\gisdata\shape\ease\" "c:\gisdata\shape\ease\" COPY "i:\gisdata\shape\fldplain\" "c:\gisdata\shape\fldplain\" COPY "i:\gisdata\shape\grids\" "c:\gisdata\shape\grids\" COPY "i:\gisdata\shape\inch50\" "c:\gisdata\shape\inch50\" COPY "i:\gisdata\shape\intersec\" "c:\gisdata\shape\intersec\" COPY "i:\gisdata\shape\laterals\" "c:\gisdata\shape\laterals\" COPY "i:\gisdata\shape\limits\" "c:\gisdata\shape\limits\" COPY "i:\gisdata\shape\plats\" "c:\gisdata\shape\plats\" COPY "i:\gisdata\shape\presslns\" "c:\gisdata\shape\presslns\" COPY "i:\gisdata\shape\ss\" "c:\gisdata\shape\ss\" COPY "i:\gisdata\shape\ssstr\" "c:\gisdata\shape\ssstr\" COPY "i:\gisdata\shape\streams\" "c:\gisdata\shape\streams\" COPY "i:\gisdata\shape\streetcl\" "c:\gisdata\shape\streetcl\" COPY "i:\gisdata\shape\streets\" "c:\gisdata\shape\streets\" COPY "i:\gisdata\shape\surveys\" "c:\gisdata\shape\surveys\" COPY "i:\gisdata\shape\tlots\" "c:\gisdata\shape\tlots\" exit
I take, this is not what you are after or is it? I mean, that's the actual deal the script you posted does.
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#145195 - 2005-08-10 02:01 PM
Re: Need a Script Check
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Shouldn't
Code:
ELSE $Result = -3 ; '-3'=File2 couldn't be open (nonexistant)
be
Code:
ELSE if $Result = -3 ; '-3'=File2 couldn't be open (nonexistant)
|
|
Top
|
|
|
|
#145197 - 2005-08-10 02:16 PM
Re: Need a Script Check
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
So taking advantage arrays, your code might look something like this
Code:
$sourceDir = 'i:\gisdata\shape\' $destDir = 'c:\gisdata\shape\' $checkFile = 'DONOTDELETE-GISscript.txt' $subDirs = 'airport','bldgs','bmarks','cbs','dwgs','ease','fldplain','grids', 'inch50','intersec','laterals','limits','plats','presslns','ss', 'ssstr','streams','streetc1','streets','surverys','tlots'
if ingroup ("GISSHAPES") $Result = CompareFileTimes($sourceDir + $checkFile, $destDir + $checkFile) if $Result = -3 or $Result = 1 for each $dir in subDirs if $Result = -3 md $destDir + $dir endif copy $sourceDir + $dir $destDir + $dir next copy $sourceDir + $checkFile $destDir + $checkFile endif endif
|
|
Top
|
|
|
|
#145201 - 2005-08-10 06:57 PM
Re: Need a Script Check
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Well i had to leave something for you to do
Glad to see it worked...
|
|
Top
|
|
|
|
#145206 - 2005-08-11 01:13 AM
Re: Need a Script Check
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
I guess if he added the trailing backslash to all of the vals in the $subDirs array (or during the copy), then the md command would be useless.
From the Copy Command portion of the 4.22 chm
Quote:
; If the target (directory) does not exist, ; and the target specification does not have a ; trailing backslash, COPY will fail with an ; errorcode 3 ("path not found") COPY "S:\MyDir\" "S:\NewDir" ; fails if NewDir does not exist
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|