Page 1 of 1 1
Topic Options
#198843 - 2010-06-16 02:25 PM DirList UDF problem
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Hi,

A very quick question regarding DirList(). I seem to recall the instructions for this UDF state that it will return an empty string if no files matching the file mask are found. How do you check for this? Also, say for instance I am trying to find the number of *.XLS files in a folder, I will use the UBOUND function on the array that DirList returns to tell me how many there were. Obviously this number is always 1 less than the 'true' number as arrays are counted from zero upwards. If there is only 1 file then the answer is 0. The answer is still zero if there are zero files found though it seems.... can anyone help?

Thanks

Top
#198844 - 2010-06-16 02:49 PM Re: DirList UDF problem [Re: kelp7]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
If no files match and it returns 0 then you can check if there is something in element[0] like this.

 Code:
Break on

;Fill the $files variable here using the DirList or another UDF.

If UBound($files) = 0
	;The line below can be left out.
	;I always use it to be 100% sure the there are no leading or tailing spaces.
	$files[0] = Trim $files[0]
	If Len($files[0]) = 0
		? "no files found"
	Else
		? "1 file found"
	EndIf
Else
	? "More then 1 files found"
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#198845 - 2010-06-16 03:21 PM Re: DirList UDF problem [Re: Mart]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
That's perfect. Thanks Mart, extremely helpful and quick answer \:\)
Top
#198846 - 2010-06-16 05:03 PM Re: DirList UDF problem [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Actually, i've just done a bit more testing and it's weirder than it first seemed.

I was searched for *.XLS using DirList()

I decided to rename the single XLS file I had in the folder DirList was searching to a .XLS2 file extension. Seems that DirList() still picks up an ".XLS2" file even if you're just searching for "*.XLS"

So the result 0 was actually correct (based on the strange functionality of DirList())

When I renamed the extension to .TXT and re-ran my code, in fact DirList() returns a UBOUND result of -1 which is great, just what I needed!

I guess it's not expecting a four character long file extension and just ignoring anything past the usual three characters which is why it still counted a ".XLS2" file as a ".XLS" file....!

Don't know if this info helps anyone.

Top
#198847 - 2010-06-17 03:47 PM Re: DirList UDF problem [Re: kelp7]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Apparently, the DIR() function in kix isn't discriminating the file extensions properly. DirList uses the built-in DIR function to enumerate the files. DirPlus uses FSO, which should not exhibit this issue and has additional features. I still prefer DirPlus as it is faster when dealing with large directory structures.

There's an updated version of DirList (v1.3g) on my web site that I used to get around this issue. It will properly return "*.xls" files or "*.xlsx". To emulate the current behavior, specify "*.XLS*".

Our entire UDF library is published nightly to the Resources / Kixtart UDF Library section on our web site (URL in signature below).

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#198848 - 2010-06-17 04:26 PM Re: DirList UDF problem [Re: Glenn Barnas]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Originally Posted By: Glenn
Apparently, the DIR() function in kix isn't discriminating the file extensions properly


That's being a little unfair. It's actually functioning correctly.

Try this at a command line:
 Code:
D:\temp>copy nul: test.123
        1 file(s) copied.

D:\temp>copy nul: test.1234
        1 file(s) copied.

D:\temp>dir *.123
 Volume in drive D is Data
 Volume Serial Number is FC87-58C4

 Directory of D:\temp

17/06/2010  15:20                 0 test.123
17/06/2010  15:20                 0 test.1234
               2 File(s)              0 bytes
               0 Dir(s)  10,175,983,616 bytes free


So, what's going on?

Well, if you try the /X flag it all becomes clear:
 Code:
D:\temp>dir /X *.123
 Volume in drive D is Data
 Volume Serial Number is FC87-58C4

 Directory of D:\temp

17/06/2010  15:20                 0              test.123
17/06/2010  15:20                 0 TEST~1.123   test.1234
               2 File(s)              0 bytes
               0 Dir(s)  10,175,983,616 bytes free


When you create the file with the long extension Windows automatically creates a 8.3 file name for backwards compatibility, and for the extension it simply truncates it to the first three characters.

Now, when you dir *.123 the command doesn't know whether you mean the full file name or the 8.3 file name so matches both.

You can disable the 8.3 file name creation using the FSUTIL command, which has the added benefit of improving the file system performance.

Top
#198867 - 2010-06-21 03:24 PM Re: DirList UDF problem [Re: Richard H.]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Thanks for all the great info in this thread.

Is there any help or support for kix2exe anywhere?

I've converted my script into an executable via kix2exe and am using it in our novell login scripts. On occasion users get an error and the script fails to run. You can see the error here where i've uploaded it:

http://kix2exe.atspace.com/

but if this isn't the right place to ask then don't worry about it \:\)
Just wondered if anyone else has ever seen this. I thought I had cured it by putting it at the end of our login scripts as it seemed to be a timing issue when other scripts written by other people were trying to run at the same time. (A SLEEP command in my kix script itself didn't seem to help)

Okay, well, thanks!

Top
#198868 - 2010-06-21 03:43 PM Re: DirList UDF problem [Re: kelp7]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
The author of k2e comes around here on occasions. I would either start a new thread with your issue or try contacting him directly. I'd also make sure to download the most current version, and repackage your script.

http://kix2exe.ramonitor.nl/contact.php

Top
#198869 - 2010-06-21 05:33 PM Re: DirList UDF problem [Re: Allen]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Thanks. One of the things I tried when discovering this problem was repackaging with the latest version of kix2exe. I will see if I can get in contact if the problem persists, thanks again.
Top
#199038 - 2010-07-19 10:28 AM Re: DirList UDF problem [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Hi again,

I have one more query about this DirList() UDF. Is there a way to stop it finding hidden files? It seems to include all files matching the wildcard whether they're hidden or not.

thanks

Top
#199048 - 2010-07-19 11:53 PM Re: DirList UDF problem [Re: kelp7]
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I may be biased... but the UDF dirplus() can exclude hidden...

$files = dirplus('c:\path','/a-h')

Or, you can pass the array from DIRList() though a 1 pass loop, and use GETFILEATTR to see if the file is hidden or not.
 Code:
for each $file in $files
	if not (getfileattr($file) & 2)
		?  $file "	is not hidden"
	endif
next


should only display the files that are not hidden.

Top
#199057 - 2010-07-21 11:35 AM Re: DirList UDF problem [Re: Bryce]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Okay, thanks for that! I didn't really want to have any more loops in my code so I may look into dirplus but possibly just leave it as it is. It's only causing a very occasional issue, hardly ever in fact so it's not too much of a problem really. Thanks again.
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
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.064 seconds in which 0.023 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org