#30319 - 2002-10-09 09:27 PM
Re: If...else...endif statement
|
Waltz
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
|
|
|
|
#30323 - 2002-10-09 10:30 PM
Re: If...else...endif statement
|
professor
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
|
Top
|
|
|
|
#30324 - 2002-10-09 11:14 PM
Re: If...else...endif statement
|
kholm
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
|
|
|
|
#30327 - 2002-10-10 01:47 PM
Re: If...else...endif statement
|
Waltz
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 , but only for the first iteration of your while loop... ,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
Fresh Scripter
Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
|
Alright, I'm back for today 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
|
|
|
|
#30331 - 2002-10-10 11:04 PM
Re: If...else...endif statement
|
professor
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 [ 10. October 2002, 23:05: Message edited by: professor ]
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 528 anonymous users online.
|
|
|