mIRC Home    About    Download    Register    News    Help

Print Thread
#267849 09/10/20 05:45 PM
Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
I don't suppose there's $noext is there? to take the extension off a filename

could use $gettok. $noext might just be tidier

Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Code
alias noext return $gettok($1,-2--,46)

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
That returns $null if the filename already has no extension. $gettok(string,1--2,46) would do it, but then it gets messy if you have a longfilename where the folder contains a period but the filename doesn't, so you'd need to use $nofile and $nopath, strip the extension, then join them back together.

Joined: Dec 2019
Posts: 45
Q
quartz Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Dec 2019
Posts: 45
what do the double dashes in gettok do out of interest? the --

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
1. the 1st is a hyphen, the 2nd is a negative https://en.wikichip.org/wiki/mirc/identifiers/$gettok

2. The $gettok also would not properly handle filename like: "Up Up and Away....jpg"

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Hello, there is $file() which has various property, including .name, which will give you the name of the file without its extention, but that only works for existing filename.

$nopath works with string though, and can be used on non existing filename, get the position of the last dot in the filename string and get only the portion before that:

Originally Posted by Using maroon's example
//var %n $nopath(Up Up and Away....jpg),%p $pos(%n,.,$calc($pos(%n,.,0) - 1)) | echo -ag > $left(%n,%p)


A handy regex can also do the job: $regsubex($nopath(Up Up and Away....jpg),\.[^.]+$,)


Edit: the $nopath/$pos code only works when there is an extention but can be fixed with some if on %p or something, wheareas I did make the regex works even if there's no extention.



Last edited by Wims; 12/10/20 12:06 AM. Reason: details

#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard