Page 2 of 4 <1234>
Topic Options
#30298 - 2002-10-07 11:24 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
Waltz, the DirPlus() looks pretty useful, but I don't know exactly how to use it. It looks pretty complicated.
Top
#30299 - 2002-10-07 11:30 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
I don't need to find folders, Lothian, I need to get all the subdir included to my EXIST statement.
Thanks anyway though

[ 07. October 2002, 23:31: Message edited by: professor ]

Top
#30300 - 2002-10-08 12:21 AM Re: If...else...endif statement
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Professor,

That's true, but DirPlus doesn't do what you want either. I was just suggesting you could adapt this UDF to do what you want. In my opinion, while both can be adapted to do what you want, FindLargeFolders has more of the elements you want than DirPlus has. Unfortunately, it does use COM which does complicate things.

Jack

[ 08. October 2002, 00:23: Message edited by: Jack Lothian ]
_________________________
Jack

Top
#30301 - 2002-10-08 12:27 AM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Professor:

You might want to read the FAQ section for some basic info about KiXtart scripting and how to use UDFs.

You might also want to explain your problem to us because I think what you try to accomplish is pretty messed up and we might be able to help you re-word the problem in such a way that it is easily scriptable.

[ 08. October 2002, 22:18: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

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

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
Alright, here is my problem. Ignore my first post since it has been resolved.
The statement in which the script searches for the existance of a .dgn file in the given variable folder is where I'm having problems. The basic EXIST() function only searches the folder to which you specify, in other words, it doesn't search the sub-dirs of the specified folder.

**How do I create an IF EXIST() statement that will not only check the files in C:\MyFolder, but also the files in C:\MyFolder\SubFold and C:\MyFolder\SubFold\SubFold etc...all together?

Do you understand what I mean now?

[ 08. October 2002, 21:23: Message edited by: professor ]

Top
#30303 - 2002-10-08 09:23 PM Re: If...else...endif statement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, why is dirplus() no goodie?
it just looks to do what you want.
 
_________________________
!

download KiXnet

Top
#30304 - 2002-10-08 10:21 PM Re: If...else...endif statement
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Professor,
In a prior post you say "I don't need to find folders, Lothian, I need to get all the subdir included to my EXIST statement" but EXIST only works on one dir at a time.

Therefore you DO need to find all the sub-folders so that you can do an EXIST on those too.

The DirPlus() and FindLargeFolders() UDFs use recursion. The very same sort of thing you must do to acheive your objective.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#30305 - 2002-10-08 10:22 PM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I think you do have a conceptual problem. IF and EXIST are two different things. IF is a conditional clause whereas EXIST check for the existance of the specified file. EXIST does not search a directory, however, if the provided filename contains placeholders, it check whether there is any file that matches the provided filename.

If you want to search directories for specific files, then you will need to use some kind of recursive dIR() function, for example the DIRPLUS() UDF that was recommended to you.
_________________________
There are two types of vessels, submarines and targets.

Top
#30306 - 2002-10-08 10:22 PM Re: If...else...endif statement
Waltz Offline
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
#30307 - 2002-10-08 11:44 PM Re: If...else...endif statement
professor Offline
Fresh Scripter

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
DirPlus looks like it might work now that you've spelled it out for me. Seeing it all together makes it look better. Give me a while to try it out
Top
#30308 - 2002-10-09 02:03 AM Re: If...else...endif statement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
seeing the dirplus here makes me wonder...

where has bryce gone?
 
_________________________
!

download KiXnet

Top
#30309 - 2002-10-09 02:17 AM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
professor...

It's easier than it first appears, n'est-ce pas? [Wink]

Keep the BB posted with your progress...

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

Top
#30310 - 2002-10-09 03:46 AM Re: If...else...endif statement
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Jooel,

Bryce was on the board most of last week. His name appeared in the list of members active during most of the days when I was on. I think he just has less time to actively participate.
_________________________
Jack

Top
#30311 - 2002-10-10 12:54 AM Re: If...else...endif statement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
copy that.
_________________________
!

download KiXnet

Top
#30312 - 2002-10-09 05:36 PM Re: If...else...endif statement
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Yep, i am still here....lurking [Big Grin]

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 Offline
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 [Roll Eyes] . 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
#30314 - 2002-10-09 07:54 PM Re: If...else...endif statement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
That's simple. Every time it finds a .DAT file it executes the $cmdstr. The question is, what you you really want to do? Just copy each .DAt file that is found or copy the whole directory if there is a .DAt file inside the directory? If it's the former then you'll need to modify $cmdstr so that it only copies that particualr file.

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

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

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
I want it to copy the directory it's in only one time if the ".dat" file is present.
Top
#30316 - 2002-10-09 08:43 PM Re: If...else...endif statement
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
;pseudo-code suggestion
;
; track the folder names and copy
; only when the folder name changes
;
;$oldfolder=""
;$newfolder=(just the folder name extracted from $item)
;if $newfolder<>$oldfolder
; do the copy thingy
;endif
;$oldfolder=$newfolder

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

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

Registered: 2002-10-02
Posts: 34
Loc: Bartow, Florida
I don't understand what you're doing there. How does tracking whether the names change or not help the situation with the script copying mult times?
Top
Page 2 of 4 <1234>


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

Who's Online
1 registered (Allen) and 496 anonymous users online.
Newest Members
Raoul, Timothy, Jojo67, MaikSimon, kvn317
17875 Registered Users

Generated in 0.072 seconds in which 0.024 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