Morthawt Posted May 7, 2011 Share Posted May 7, 2011 (edited) How can I get the .ext from a file that is chosen from a fileopendialogue? I know I could use the . as a delimiter some how, but I do not know how to just get that. Lets say they choose the file c:\users\testuser\desktop\my great screensaver.scr How can I make a variable that stores just the .scr part, to get what ever that last .something is? Thanks Edited May 7, 2011 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Morthawt Posted May 7, 2011 Author Share Posted May 7, 2011 Took some finding, but it turned out to be _PathSplit Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
wakillon Posted May 7, 2011 Share Posted May 7, 2011 Something like this ? ConsoleWrite ( "Extension : " & 'c:\users\testuser\desktop\my great screensaver.scr' & @Crlf ) Func _GetExtByFullPath ( $_FullPath=@ScriptFullPath ) $_FileName = StringSplit ( $_FullPath, '.' ) If Not @error Then Return $_FileName[$_FileName[0]] Else Return 0 EndIf EndFunc ;==> _GetExtByFullPath ( ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
guinness Posted May 7, 2011 Share Posted May 7, 2011 Also if you want to check if a file is a .scr then use UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
UEZ Posted May 7, 2011 Share Posted May 7, 2011 Here 2 other ways: $path = "c:\users\testuser\desktop\my great screensaver.scr" $ext1 = StringRegExpReplace($path, ".*(\..+)\Z", "$1") $ext2 = StringRight($path, StringLen($path) - StringInStr($path, ".", 0, -1) + 1) MsgBox(0, "Test", $ext1 & @LF & $ext2) Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
wakillon Posted May 7, 2011 Share Posted May 7, 2011 Here 2 other ways: $path = "c:\users\testuser\desktop\my great screensaver.scr" $ext1 = StringRegExpReplace($path, ".*(\..+)\Z", "$1") $ext2 = StringRight($path, StringLen($path) - StringInStr($path, ".", 0, -1) + 1) MsgBox(0, "Test", $ext1 & @LF & $ext2) Br, UEZ Your example works only if there is an extension, else it return full path ... Not mine ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Morthawt Posted May 7, 2011 Author Share Posted May 7, 2011 This is how I did it in the end: expandcollapse popup#include <Crypt.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <file.au3> Global $drive Global $dir Global $filename Global $ext Global $alg = $CALG_AES_256 #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 291, 119, 192, 124) $Label1 = GUICtrlCreateLabel("File Encryption and Decryption", 24, 16, 249, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $encrypt = GUICtrlCreateButton("Encrypt a file", 24, 56, 75, 25, BitOR($WS_GROUP, $BS_DEFPUSHBUTTON)) $decrypt = GUICtrlCreateButton("Decrypt a file", 192, 56, 75, 25, $WS_GROUP) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) $AES = GUICtrlCreateRadio("AES (Win XP and above)", 24, 38, 140, 17) GUICtrlSetState(-1, $GUI_CHECKED) $RC4 = GUICtrlCreateRadio("RC4", 194, 38, 128, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $encrypt Encryptfile() Case $decrypt Decryptfile() Case $RC4 ;MsgBox(0,'','RC4') $alg = $CALG_RC4 Case $AES ;MsgBox(0,'','AES') $alg = $CALG_AES_256 EndSwitch WEnd Func Decryptfile() $openfile = FileOpenDialog('Choose file to decrypt', @MyDocumentsDir, 'All Files (*.*)', 3) If $openfile <> '' Then $pathsplit = _PathSplit($openfile, $drive, $dir, $filename, $ext) $password = InputBox('Password', 'Enter the password', '', '*') $key = _Crypt_HashData($password, $CALG_SHA1) $savefile = FileSaveDialog('Save as', @MyDocumentsDir, 'All Files (*' & $pathsplit[4] & ')', 16) $pathsplitsave = _PathSplit($savefile, $drive, $dir, $filename, $ext) If $pathsplitsave[4] <> $pathsplit[4] Then $savefile = $savefile & $pathsplit[4] If $savefile <> '' Then If $openfile <> $savefile Then _Crypt_DecryptFile($openfile, $savefile, $key, $alg) If @error Then MsgBox(0, 'Error', 'There was an errror.') Else MsgBox(0, 'Error', 'You cannot overwrite the original file with the new file. Save as a different name.') EndIf EndIf EndIf EndFunc ;==>Decryptfile Func Encryptfile() $openfile = FileOpenDialog('Choose file to encrypt', @MyDocumentsDir, 'All Files (*.*)', 3) If $openfile <> '' Then $pathsplit = _PathSplit($openfile, $drive, $dir, $filename, $ext) $password = InputBox('Password', 'Enter the password', '', '*') $key = _Crypt_HashData($password, $CALG_SHA1) $savefile = FileSaveDialog('Save as', @MyDocumentsDir, 'File (*' & $pathsplit[4] & ')', 16) $pathsplitsave = _PathSplit($savefile, $drive, $dir, $filename, $ext) If $pathsplitsave[4] <> $pathsplit[4] Then $savefile = $savefile & $pathsplit[4] If $savefile <> '' Then If $openfile <> $savefile Then _Crypt_EncryptFile($openfile, $savefile, $key, $alg) If @error Then MsgBox(0, 'Error', 'There was an errror.') Else MsgBox(0, 'Error', 'You cannot overwrite the original file with the new file. Save as a different name.') EndIf EndIf EndIf EndFunc ;==>Encryptfile My method seems to get the whole extension. My first idea would not work with .'s in a file name like "My amazing v 0.5.32 file.cmd". Also this one will add the extension if the file save as was not manually added with the extension. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
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