Page 1 of 1 1
Topic Options
#145191 - 2005-08-10 04:03 AM Need a Script Check
StarwarsKid Offline
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
#145192 - 2005-08-10 06:42 AM Re: Need a Script Check
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, make an array of each subfolder you want to process and then just loop them through.
_________________________
!

download KiXnet

Top
#145193 - 2005-08-10 06:58 AM Re: Need a Script Check
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
I haven't worked with arrays yet (although I've read a lot about them ever since joining KiX BBS). Could you point me to some tools and perhaps some basic theory on what arrays are and how they are used?
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#145194 - 2005-08-10 07:43 AM Re: Need a Script Check
Lonkero Administrator Offline
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 Offline
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
#145196 - 2005-08-10 02:12 PM Re: Need a Script Check
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
good question.
but, who really knows?
like said, there are so many duplicates and oddities that can't really know what is ment to be there and what not.
_________________________
!

download KiXnet

Top
#145197 - 2005-08-10 02:16 PM Re: Need a Script Check
maciep Offline
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
#145198 - 2005-08-10 05:51 PM Re: Need a Script Check
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
maciep, .... .. That's.. .. beautiful. ..

I like your structure. I'll give this script modification a try and let you know how it works!
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#145199 - 2005-08-10 05:52 PM Re: Need a Script Check
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Lonkero, Thanks for the brief explaination of arrays and their uses. With your description and maciep's example I think I just might be able to grasp this concept.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#145200 - 2005-08-10 06:06 PM Re: Need a Script Check
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
maciep, I just tested your modified script. EVERYTHING works exaclty as it should. T H A N K Y O U for taking the time to rewrite my script into a working script. What a way to start the day!

I did have to add a "$" next to one of the $subDirs variables, but that was the only change.

_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#145201 - 2005-08-10 06:57 PM Re: Need a Script Check
maciep Offline
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
#145202 - 2005-08-10 07:01 PM Re: Need a Script Check
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
actually, two things.
'surverys' is misspelled.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#145203 - 2005-08-10 07:40 PM Re: Need a Script Check
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
good eye les. i'll buy a new keyboard.
Top
#145204 - 2005-08-10 08:25 PM Re: Need a Script Check
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Great eyes Les, thanks for catching that! Just made the change.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#145205 - 2005-08-10 10:39 PM Re: Need a Script Check
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
maciep, the problem is, you do dublicate job too.
ok, correct me if I'm wrong but MD just before copy is useless.
_________________________
!

download KiXnet

Top
#145206 - 2005-08-11 01:13 AM Re: Need a Script Check
maciep Offline
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
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.074 seconds in which 0.031 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