#123629 - 2004-07-23 03:04 AM
KIX function to return directory listing without the file extension.....
|
TTripn
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.
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
|
|
|
|
#123632 - 2004-07-23 03:17 PM
Re: KIX function to return directory listing without the file extension.....
|
Chris S.
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
|
|
|
|
#123634 - 2004-07-23 06:19 PM
Re: KIX function to return directory listing without the file extension.....
|
Bryce
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 342 anonymous users online.
|
|
|