#30306 - 2002-10-08 10:22 PM
Re: If...else...endif statement
|
Waltz
Seasoned Scripter
Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
|
Professor... ...and the survey says..."DirPlus()" might get you closer to what you want (as far as enumerating the folders)...
code:
; BREAK ON "Source Directory:" ? GETS $workingdir ;enter source directory "Destination Directory:" ? GETS $destdir ;enter destination directory ;stuff the dos command into a variable $cmdstr="%COMSPEC% /q /e:1024 /c XCOPY $workingdir\$projfile $DestDir\$projfile /E /I /Q" WHILE 1=1 "Project Folder Number:" ? GETS $projfile $dirplus = DIRPLUS($workingdir,"*.*",1);load array with all the (sub)folders and files FOR EACH $item IN $dirplus ;read the array element by element until array ends IF INSTR($item,".dgn"); if the element satisfies the file extension criteria ; ?$item ; uncomment this line if you want to view the items... SHELL $cmdstr ; then do the dos dance (a waltz?) ENDIF NEXT LOOP ; ;FUNCTION DirPlus() ; ;Author Bryce Lindsay(bryce@isorg.net) ; ;Action Returns an array containing a file structure of a specified folder. ; ;Syntax DirPlus("folder","mask",[subfolders],[datatype]) ; ;Parameters Folder ; the folder you want information from ; ; Mask ; the type of file mask you want to use. ; "*.*" will return everything. ; ".exe" will return everything that has a ".exe" in it. (this ; is more like a search sting, than a true file mask) ; for multiple file type seperate search patterns with a ; ; ".exe;.html;.doc" ; ; Subfolders ; Optional flag, ; 0 = do not include subfolders ; 1 = include subfolders ; ; DataType ; Optional flag ; 0 = standard filename ; 1 = return the objecthandle ; ;Remarks This is an expansion on the regular DIR() command. ; ;Returns Returns an Array of elements files with file and folder information ; of the specified folder ; ;Dependencies WSH com library is needed if you want to return the object handles. ; ;Example(s) $dir = DirPlus("%temp%","*.*") ; $dir = dirplus("$temp%,".exe",1) ; $dir = dirplus("$temp%,".dll",0,1) ; ;Source FUNCTION DirPlus($dir,$mask,OPTIONAL $subfolders, OPTIONAL $datatype) DIM $file, $subflag, $i, $ii,$pattern IF vartype($_temparray) = 0 GLOBAL $_temparray[30], $_i $_i = 0 ELSE $subflag = 1 ENDIF IF $dir = 0 EXIT(1) ENDIF IF substr($dir,len($dir),1) = "\" $dir = substr($dir,1,len($dir)-1) ENDIF IF $mask = 0 $mask = "*.*" ENDIF $mask = split($mask,";") IF exist($dir) = 0 EXIT(2) ENDIF $file = dir($dir + "\*.*") WHILE @error = 0 AND $file SELECT CASE $file = "." OR $file = ".." ;bit bucket! CASE getfileattr($dir + "\" + $file) & 16 $_temparray[$_i] = $dir + "\" + $file $_i = $_i + 1 IF $subfolders = 1 dirplus($dir + "\" + $file,"*.*",$subfolders) IF @error <> 0 EXIT(1) ENDIF ENDIF CASE 1 $_temparray[$_i] = $dir + "\" + $file $_i = $_i + 1 ENDSELECT IF ubound($_temparray) = $_i REDIM PRESERVE $_temparray[$_i + 30] ENDIF $file = dir("") LOOP
IF $subflag = 1 ; ELSE REDIM PRESERVE $_temparray[$_i-1] $dirplus = $_temparray SELECT CASE $mask[0] = "*.*" ;return all files! CASE 1 DIM $temparray[ubound($dirplus)] $ii = 0 FOR EACH $pattern IN $mask $i = 0 FOR EACH $file IN $dirplus IF instr($file,$pattern) $temparray[$ii] = $dirplus[$i] $ii = $ii + 1 ENDIF $i = $i + 1 NEXT NEXT IF $ii > 0 REDIM PRESERVE $temparray[$ii-1] $dirplus = $temparray ELSE $dirplus = 0 ENDIF ENDSELECT SELECT CASE $datatype = 0 ;return filename! CASE $datatype = 1 ;return File object handle $i = 0 $fso = createobject("scripting.filesystemobject") IF @error <> 0 AND vartype($fso) <> 9 EXIT(@error) ENDIF FOR EACH $file IN $dirplus IF getfileattr($file) & 16 $file = $fso.getfolder($file) ELSE $file = $fso.getfile($file) ENDIF $dirplus[$i] = $file $i = $i + 1 NEXT ENDSELECT $_i = 0 $_temparray = 0 EXIT(0) ENDIF ENDFUNCTION
[ 09. October 2002, 02:30: Message edited by: Waltz ]
_________________________
We all live in a Yellow Subroutine...
|
Top
|
|
|
|
#30312 - 2002-10-09 05:36 PM
Re: If...else...endif statement
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Yep, i am still here....lurking
but really all you 3k posters beat me to the reply!!
|
Top
|
|
|
|
#30313 - 2002-10-09 07:48 PM
Re: If...else...endif statement
|
professor
Fresh Scripter
Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
|
Here's what I've got to work.... code:
BREAK ON
"Source Directory:" ? GETS $workingdir
"Destination Directory:" ? GETS $destdir
WHILE 1=1 "Project Folder Number:" ? GETS $projfile
$cmdstr = "%COMSPEC% /q /e:1024 /c XCOPY $workingdir\$projfile $DestDir\$projfile /E /I" $dirplus = DIRPLUS("$workingdir\$projfile","*.*",1)
FOR EACH $item IN $dirplus IF INSTR($item,".dat") SHELL $cmdstr ENDIF NEXT LOOP
FUNCTION DirPlus()........... .............
However, there is a glitch that I don't know how to fix. It seems pretty simple though . For every item that has the extension ".dat", the entire contents of the folder is copied. EX if there are 4 files with ext ".dat", then everything is copied 4 times. I only need it copied one time. [ 09. October 2002, 20:10: Message edited by: professor ]
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 465 anonymous users online.
|
|
|