Jump to content

Recommended Posts

Posted

I am having a problem I don't have any code to show since I erased and kept redoing it.

I have a FileSaveDialog() and I want to be able to check weather or not people put a extension on when saving the file if not it will make it a simple text file.

example

if someone saves their file like this

myfile

they didn't put and extension on it so it will save it like this

myfile.txt

since *.txt is the default for my program

or if they save it like this

myfile.exe

it will create a *.exe file instead of a *.txt

and my problem is this

when they don't add a extension it makes a file with *.txt extension but when they do add a extension this is how it looks like

myfile.exe.txt

I tried StringTrimRight($String , 4) but that wouldn't work which is odd.

I hope you can understand this.

Posted

Hmm, perhaps this code example may help with checking the extension.

;~ $string = 'file.txt'
$string = 'file.exe'
;~ $string = 'file'

$count = StringInStr($string, '.', 0, -1)
If $count Then
    $extension = StringTrimLeft($string, $count)
    if $extension = 'txt' Then
        ConsoleWrite('txtfile: ' & $extension & @CRLF)
    Else
        ConsoleWrite('otherfile: ' & $extension & @CRLF)
    EndIf
Else
    ConsoleWrite('extensionless file: ' & $string & @CRLF)
    $string &= '.txt'
    ConsoleWrite('extension added: ' & $string & @CRLF)
EndIf
;~ FileWrite($string, 'text')

:D

Posted

Hmm, perhaps this code example may help with checking the extension.

;~ $string = 'file.txt'
$string = 'file.exe'
;~ $string = 'file'

$count = StringInStr($string, '.', 0, -1)
If $count Then
    $extension = StringTrimLeft($string, $count)
    if $extension = 'txt' Then
        ConsoleWrite('txtfile: ' & $extension & @CRLF)
    Else
        ConsoleWrite('otherfile: ' & $extension & @CRLF)
    EndIf
Else
    ConsoleWrite('extensionless file: ' & $string & @CRLF)
    $string &= '.txt'
    ConsoleWrite('extension added: ' & $string & @CRLF)
EndIf
;~ FileWrite($string, 'text')

:D

Yes! This works Perfect your Great!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...