Page 1 of 1 1
Topic Options
#123629 - 2004-07-23 03:04 AM KIX function to return directory listing without the file extension.....
TTripn Offline
Fresh Scripter

Registered: 2004-07-22
Posts: 8
Hi,
Is there a function in KIX that can do this?


thanks....

Top
#123630 - 2004-07-23 03:15 AM Re: KIX function to return directory listing without the file extension.....
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Any directory UDF will suffice, just make sure you strip off the extension properly. Here is an example...

Code:

$files = "file.txt", "file.1.txt", "file.1.2.txt", "file1"

For Each $file in $files
Iif(Instr($file,"."),Left($file,InStrRev($file,".")-1),$file) ?
Next


Top
#123631 - 2004-07-23 04:23 AM Re: KIX function to return directory listing without the file extension.....
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Easy for you to say Chris. Perhaps you could also explain what your code is doing so he can learn more from it.

Don't forget, you've been using KiX for quite a while now.

Top
#123632 - 2004-07-23 03:17 PM Re: KIX function to return directory listing without the file extension.....
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
For you, Doc, anything...

Code:
; Build an array with possible filename examples. Since "." is a

; valid character in a filename, one cannot simply do a Split on
; all "." delimiters. Also, a filename does not necessarily have
; to have an extension.
;
$files = "file.txt", "file.1.txt", "file.1.2.txt", "file1"

; Enumerate the array.
For Each $file in $files
Iif( ; There are two possible returns, one with a file extension
; and one without. Therefore the Iif function is a good choice.
Instr($file,".")
; First parameter of Iif. If there is a "." in the filename,
; the characters after will be considered the file extension.
,Left($file,InStrRev($file,".")-1)
; Second parameter of Iif, which is the return value if parameter
; one is TRUE. Uses InStrRev to find the first "." going from
; right to left, subtracts one from the return value of InStrRev,
; then uses that value to return all of the characters to the Left
; of that value.
,$file) ?
; Third parameter of Iif, this is the return value if parameter
; one is FALSE. Since there is no "." character in the string,
; simply return the filename.
Next


Top
#123633 - 2004-07-23 03:29 PM Re: KIX function to return directory listing without the file extension.....
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Very nice commenting, Chris.

You forgot to explain the '?' though.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#123634 - 2004-07-23 06:19 PM Re: KIX function to return directory listing without the file extension.....
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Does not the OS treat anything past the last "." as a file extension?

you can use split...

Code:

$files = "file.1.txt","file.txt","file","file.html","file.txt.html"
for each $file in $files

$file = split($file,".")
if ubound($file) > 0
? join($file,".",ubound($file))
else
? join($file,".")
endif

next



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 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.043 seconds in which 0.018 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