Page 3 of 4 <1234>
Topic Options
#30318 - 2002-10-09 09:18 PM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Because you want to initiate the copy only if the foldername changes. However, this would assume that the folders are sorted since you might have multiple .DAT files in any given folder.
So, you should do the following:
1) Retrieve all folders containing a .DAT file into an array
2) Sort the array (e.g. BubbleSort, QSort)
3) Copy folder to new destination if foldername not equal previous foldername

[ 09. October 2002, 21:25: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#30319 - 2002-10-09 09:27 PM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
{Edit} Somewhere along the line *.dgn has transformed into *.dat {/Edit}
This is UNTESTED, but gives you the logic, I think...
code:
WHILE 1=1 "Project Folder Number:" ? 
GETS $projfile
$dirplus = DirPlus($workingdir\$projfile,*.*",1)
$oldfolder=""
FOR EACH $item IN $dirplus
$offset=INSTRREV($item,"\") ; find the last backslash in $item
$newfolder=SUBSTR($item,1,$offset-1) ; save the 'new' folder name only
IF INSTR($item,".DAT") AND $newfolder<>$oldfolder ; folder names don't match
SHELL $cmdstr ; do the copy
ENDIF
$oldfolder=$newfolder ; save the 'new' as the 'old' folder name
NEXT
LOOP



[ 09. October 2002, 23:11: Message edited by: Waltz ]
_________________________
We all live in a Yellow Subroutine...

Top
#30320 - 2002-10-09 09:45 PM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Jens: I figured dirplus() returned the elements sorted already on the assumption that it was reading the tree from the top down??
I know, I know, never assume anything. [Big Grin]
_________________________
We all live in a Yellow Subroutine...

Top
#30321 - 2002-10-09 09:49 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
That's great Waltz, but the problem remains. As long as the COPY statement is inside of the FOR EACH function, then every time a file with the ext .dat if found it is going to copy all of the files in that folder. I only want it to copy them one time.

[ 09. October 2002, 21:50: Message edited by: professor ]

Top
#30322 - 2002-10-09 10:16 PM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
As I already stated, you need to adjust the $cmdstr to reflect the directory that you want to copy from. You might want to take a step back and think about what you try to do. It might even help to write it down on a piece of paper. I'm slowly feeling like going in circles. We are definitely willing to help you if you are willing to learn. Thus, please take a moment and study the code fragments provided to you.

Next question, what do you wan to do with a subdirectory inside a directory that contains a .DAT (or whatever) file does this one need to be copied, too? What if this one has it's own .DAt file? Does it go into a different directory on the target?
_________________________
There are two types of vessels, submarines and targets.

Top
#30323 - 2002-10-09 10:30 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
If the Project Folder has any .dat files in it(whether in subdir or not) I want to copy the entire Project Folder(without renaming or changing anything in it) to the destination folder.

I'm just getting confused about what you're trying to do with the newfolder and old folder is all, and I'm kinda tired today [Smile]

Top
#30324 - 2002-10-09 11:14 PM Re: If...else...endif statement
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Professor,

I quess you are nursing your users more than nessasary, would it be to mutch to ask them to save any new projects in the same folder or subfolders under this, like C:\Projects, and then you will guarantee a backup off that folder ?

If you have just one folder to check you could use RoboCopy from the ressource kit

If this is the doings of an application, i would still suggest RoboCopy.

For a RoboCopy-like solution for Win9x, look here;
Using KiXtart to syncronize directories

(This is an old post, could be improved by using newer KiX functions)

If you want an oversight of all folders containing a .DAT file, DirPlus() could me moderated to do that.

What is your objebtive by this task, have I missed something, ore haven’t you described it?

Top
#30325 - 2002-10-09 11:22 PM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Here's my take at this point...
1.My testing shows that DIRPLUS() returns the tree sorted top down as assumed...
2.It is copying the dir if a dat file is found, as expected.
3.The issue(?)is that it is copying the dir repeatedly instead of just once.
4.The oldfolder-newfolder construct is wonky as it stands; the logic needs to be tweaked.
5.I'm done for today, also...
_________________________
We all live in a Yellow Subroutine...

Top
#30326 - 2002-10-09 11:45 PM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Actually, we can now simplify everything. Use DirPlus() to search for a *.DAT file in the project directory and any subdirectories. If DirPlus() return anything then copy the complete project folder including every sub folder. If DirPlus() doesn't return anything, don't copy.

It doesn't matter what exactly will be returned since we're copying everything anyway. The only time the copy will not be performed is if there is no .DAT (or whatever the current extension is) file present at all.
_________________________
There are two types of vessels, submarines and targets.

Top
#30327 - 2002-10-10 01:47 PM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Professor...
Added another udf - Combsort() - which you will have to include in your script. This sorts the array, per Jens' suggestion, although in my environment it doesn't seem necessary. Changed the file 'mask' to .dat in place of *.* and renamed the old-new thingy to previous and current which should help you to understand the logic...
In my limited test, the folder\subfolder\file enumeration seems to be working as specified [Smile] , but only for the first iteration of your while loop... [Frown] ,and kinda brings you full circle to your much earlier 'endless' loop quandry...

code:
WHILE 1=1 "Project Folder Number:" ? 
GETS $projfile
$dirplus = DirPlus("$workingdir\$projfile",".DAT",1) ; gather folders with .dat file(s)into array
$dirplus = CombSort($dirplus) ; sort the array into ascending order
$previousfolder="" ; initialize folder path 'bookmark'
FOR EACH $item IN $dirplus ; read the array one at a time until end of array
$offset=INSTRREV($item,"\") ; find the last backslash in the path
$currentfolder=SUBSTR($item,1,$offset-1) ; save the current folder path
IF $currentfolder<>$previousfolder ; if folder paths don't match
? "item" $item ; show me what folders are on the dance card
SHELL $cmdstr ; do the dos dance
ENDIF
$previousfolder=$currentfolder ; save current folder path as previous folder path
NEXT
LOOP

and here's the udf code to be included
code:
 ;CombSort() 
;Action:
;Sort a kixtart array using the combsort algorithm (the smart bubble).
;Syntax:
;array = combsort( array [, order ])
;Parameters:
;Array (Required) - A single dimensional kixtart array
;Order (Optional) - The sort order (0/1). If omitted or set to zero, the
;array will be sorted in ascending order. If set to 1, the array will be sorted
;in descending order.
;Returns:
;The sorted array
;Example(s):
;$array = Peach,Pumpkin,Orange,Grape,Lime,Apple,Rasberry,Cherry,Lemon
;
;$array = combsort($array) ; sort ascending
;for each $element in $array
; ? $element
;next
;$array = 1,2,3,4,5
;$array = combsort($array,1) ; sort descending
;for each $element in $array
; ? $element
;next
;$array = combsort(split("Z Q G A D M U V N C B T W J X S K R H I L E F P O Y"))
;for each $letter in $array
; ? $letter
;next
;
;Source:
;
function combsort($v, optional $o)
dim $i,$j,$m,$s,$g
$n=ubound($v)
$g=$n
if $g
while $g > 1 or not $s
$g=($g*1000)/1279
if $g < 1
$g=1
endif
$s=1
for $i = 0 to $n-$g
$j=$i+$g
if ($v[$i] > $v[$j] and not $o) or ($v[$i] < $v[$j] and $o)
$m = $v[$i]
$v[$i] = $v[$j]
$v[$j] = $m
$s=0
endif
next
loop
$combsort = $v
else
$combsort = 0
endif
endfunction

Cheers...

[ 10. October 2002, 19:53: Message edited by: Waltz ]
_________________________
We all live in a Yellow Subroutine...

Top
#30328 - 2002-10-10 09:14 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
Alright, I'm back for today [Smile] Just to let you all know what I'm using this for, I work in the Dept of Transportation in Florida, and when users finish a project they save it onto the server with the following structure:

\\dotD1\160003645 *(project number folder)*
inside 160003645 are the folders:
drainage, structures, right of way, existing dgn, proposed dgn...and so forth.

I get a list of project numbers(about 200) every month to search the server for and burn onto a CD to return to Tallahassee(main office). Instead of actually having to look through the folders and see if every one has a .dgn file, .dat file, .key file...etc to make sure the project was complete, I was asked to create a script to do the same thing with less effort. Hopefully this helps with reasoning behind my inquery.

By the way, thanks for all of your time and effort so far on this project. I know that you don't really have to help me, but I appreciate it!

Top
#30329 - 2002-10-10 09:58 PM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Are you making any headway with the loop de loop?
_________________________
We all live in a Yellow Subroutine...

Top
#30330 - 2002-10-10 10:46 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
I used the previous script that was posted, although it still copies the folder more than one time depending on the number of requested files found. Is there any way that the $cmdstr could be taken out of the FOR EACH function? That's what is causing it to copy so many times.
Top
#30331 - 2002-10-10 11:04 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
Why won't something like this work:
code:
WHILE 1=1 
COLOR w+/n
?"Project Folder Number:" ?
COLOR n/n
GETS $projfile
$cmdstr = "%COMSPEC% /q /e:1024 /c XCOPY $workingdir\$projfile $DestDir\$projfile /E /I"
$dirplus = DirPlus("$workingdir\$projfile","*.*",1)
IF INSTR($dirplus,"*.dat")
SHELL $cmdstr
ENDIF
LOOP


Remember now, I'm not an expert at this [Wink]

[ 10. October 2002, 23:05: Message edited by: professor ]

Top
#30332 - 2002-10-10 11:32 PM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Because DirPlus returns an array and you cannot use INSTR with an array. Thus you'll have to use UBOUND to check whether the returned variable is an array. If it is, then copy the folder. It''s all been stated already throughout this thread.
_________________________
There are two types of vessels, submarines and targets.

Top
#30333 - 2002-10-11 08:09 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
How do I use UBOUND then? What is the syntax?
Top
#30334 - 2002-10-11 08:11 PM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Please take a look at the KiXtart Manual, it ewxplains how to use UBOUND(). If UBOUND() returns -1, then the variable is not an array. You can achieve the same by using (VARTYPE($var) & 8192), if that one is '0' then it's not an array.
_________________________
There are two types of vessels, submarines and targets.

Top
#30335 - 2002-10-11 08:12 PM Re: If...else...endif statement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ubound($var)
also using vartype or vartypename gives you the info.

all those are kixtart inbuild functions.
Ubound()
Vartype()
Vartypename()
_________________________
!

download KiXnet

Top
#30336 - 2002-10-11 08:24 PM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Go here to download Kix Help Manual ver 411 in HTML format
_________________________
We all live in a Yellow Subroutine...

Top
#30337 - 2002-10-11 08:37 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
What does 8204 mean?
Top
Page 3 of 4 <1234>


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

Who's Online
0 registered and 370 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.075 seconds in which 0.025 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