Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / File Request Extension?

Author
Message
Mugen Wizardry
User Banned
Posted: 12th Dec 2010 16:12 Edited at: 12th Dec 2010 16:13
Hi all, I found this code, but it doesn't have an extension finder. If you select a file, I need it to say the file extension instead of the filename. So "myfile.dat" would be ".dat"

Here's the code:



CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Dec 2010 16:37
If it's standard it should allow you to use the * in the place of the filename like "*.dat" to get all files with the .dat extension.

Mugen Wizardry
User Banned
Posted: 12th Dec 2010 16:38 Edited at: 12th Dec 2010 16:39
thanks, but i actually need to use the file extension in an if statement.

Here's what I have so far:



i need it to return ".fileext" NOT "fileext"

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 12th Dec 2010 17:07 Edited at: 12th Dec 2010 17:11


is this what you want?

>Edit<
Sorry,I think I was assuming your code worked.

This is how I would do it...

assuming fn$ is the file name



This will return the last 4 characters of the filename.

e.g ".dat", ".exe", ".jpg" etc

Only works with 3 character extensions tho.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Dec 2010 17:08 Edited at: 12th Dec 2010 17:11
You can use IanMs Matrix 1 Utilities Plugin to quickly take out the extension.



Edit: Works for any size extension.

Mugen Wizardry
User Banned
Posted: 12th Dec 2010 17:09 Edited at: 12th Dec 2010 17:11
edit:

for some reason, the above command, even though i have ianm's plugins, it says could not understand command.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Dec 2010 17:13
You may have to reinstall IanMs Plugin:

Here's a direct link to download the latest version:
https://forumfiles.thegamecreators.com/download/2128448

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 12th Dec 2010 17:13
Just extract it using the string commands, starting from the last character working backwards until you hit the period character.
Mugen Wizardry
User Banned
Posted: 12th Dec 2010 17:19
The above code works just fine after I replaced the plugins! Thanks guys!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 12th Dec 2010 17:22


Just so I'm happy, here's a working snippet from me as well

This one works with any sized extension name.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Dec 2010 17:28 Edited at: 12th Dec 2010 17:31


[edit]Grog's is probably a little more efficient than mine, but need to be added to so that a filename without an extension is dealt with correctly.

Mugen Wizardry
User Banned
Posted: 12th Dec 2010 17:30
thanks guys!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 12th Dec 2010 17:32
@IanM:
That is almost beautiful in its simplicity.

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 12th Dec 2010 17:36
Well, you can scan the file name for the extension like this
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Dec 2010 18:23 Edited at: 12th Dec 2010 18:25
Quote: "[edit]Grog's is probably a little more efficient than mine, but need to be added to so that a filename without an extension is dealt with correctly."


Yeah, mine wouldn't work properly if there was no period.



When testing the above code it crashes out saying that ntdll.dll stopped working because it sees INSTR(). I'm using Vista 64... help IanM!

Test Code:


Mugen Wizardry
User Banned
Posted: 12th Dec 2010 19:34
Here is a fix for if you try to cancel a file save or load, and it crashes saying 'Use positive integer':



Enjoy! ^^

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 12th Dec 2010 20:29


Works in all cases.

Cheers!
Sven B

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Dec 2010 21:10
Quote: "When testing the above code it crashes out"

The problem is with the EXITFUNCTION command. It's not safe to return a literal string from a function - return either a variable or temporary via an expression instead.


For your code, I was actually suggesting:


Mugen Wizardry
User Banned
Posted: 12th Dec 2010 21:21
I see.

Thanks IanM!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Dec 2010 09:23
Quote: "The problem is with the EXITFUNCTION command. It's not safe to return a literal string from a function - return either a variable or temporary via an expression instead."


Ah, ok. I'm glad it wasn't your plugin.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Dec 2010 14:03
Nice one liner there Sven B!

There's more than one way to skin a cat

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 13th Dec 2010 19:09
Quote: "Nice one liner there Sven B!"


Thanks, I like those fast commands IanM created. Even my code looks faster now, showing off its speed, not just the program
Can't hate that right?

Sven B

Login to post a reply

Server time is: 2026-07-21 04:20:16
Your offset time is: 2026-07-21 04:20:16