NewBe Posted January 30, 2008 Posted January 30, 2008 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.
MHz Posted January 30, 2008 Posted January 30, 2008 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')
NewBe Posted January 30, 2008 Author Posted January 30, 2008 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') Yes! This works Perfect your Great!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now