z0mgItsJohn Posted January 19, 2009 Share Posted January 19, 2009 This Function Allows You To Get The "Real" Name Of The File Without The Extension For Example You Have "Test.Au3" And You Want To Know What The File Is Called Without The ".Au3" You Can Use This Function To Get That.. Enjoy! Also.. If You Have A File For Say "This..Is..A..Test.Au3" It Will Return "This..Is..A.Test".. ; Source : _FileGet_RealName.Au3 #Include <String.Au3> Func _FileGet_RealName ($File) Local $String, $Return If StringInStr ($File, '.') = '0' Then Return $File ElseIf $File = '' Then Return $File EndIf $String = StringSplit ($File, '') For $Array = $String['0'] To '1' Step '-1' If $String[$Array] <> '.' Then $Return = $Return & $String[$Array] Else $Return = _StringReverse ($Return) $Return = '.' & $Return $Return = StringReplace ($File, $Return, '') ExitLoop EndIf Next Return $Return EndFuncoÝ÷ Ù*.ÇÅ©©à.Ý«¢+Ø%¹±Õ±Ðí}¥±Ñ}I±9µ¹ÔÌÐì((ÀÌØí¥±|ÄôÌäíQ¡¥Ì¸¹%̸¹¸¹QÍйÔÌÌäì(ÀÌØíI±}9µ|Äô}¥±Ñ}I±9µ ÀÌØí¥±|Ĥ((ÀÌØí¥±|ÈôÌäíÕѽ%и¹%̸¹Q¹ÔÌÌäì(ÀÌØíI±}9µ|Èô}¥±Ñ}I±9µ ÀÌØí¥±|Ȥ()5Í ½à ÌäìÀÌäì°ÌäíIÍÕ±ÑÌÌäì°Ìäí¥±ÄèÌäìµÀìÀÌØí¥±|ĵÀì I1µÀìÌäíI°9µèÌäìµÀìÀÌØíI±}9µ|ĵÀì I1µÀìÌäí¥±ÈèÌäìµÀìÀÌØí¥±|ȵÀì I1µÀìÌäíI°9µèÌäìµÀìÀÌØíI±}9µ|È°ÌäìÀÌäì¤ ~ Enjoy ~ Please Leave Comments Etc.. Etc.. - John Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
GEOSoft Posted January 19, 2009 Share Posted January 19, 2009 (edited) MsgBox(0, "Resuts", _FileGet_RealName("AutoIt..Is..FTW.Au3")) MsgBox(0, "Resuts", _FileGet_RealName(@DesktopDir & "\Test.au3")) Func _FileGet_RealName($sFile) $sFile = StringRegExpReplace($sFile, "(?i).*[[:punct:]](\w*?)\..*", "$1") If @Extended >= 1 Then Return $sFile Return "" EndFunc Edited January 19, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
z0mgItsJohn Posted January 19, 2009 Author Share Posted January 19, 2009 MsgBox(0, "Resuts", _FileGet_RealName("AutoIt..Is..FTW.Au3")) MsgBox(0, "Resuts", _FileGet_RealName(@DesktopDir & "\Test.au3")) Func _FileGet_RealName($sFile) $sFile = StringRegExpReplace($sFile, "(?i).*[[:punct:]](\w*?)\..*", "$1") Return $sFile EndFunc Umm.. That Dose Not Support... Stuff Like "AutoIt..Is..FTW.Au3" Example.. expandcollapse popup#Region Yours... $Var1 = _FileGet_RealName2 ('This..Is..A..Test.Au3') ; $Var = Test ; Not "This..Is..A..Test" ConsoleWrite ('$Var1 : ' & $Var1 & @CRLF) $Var2 = _FileGet_RealName2 ('Test..Au3') ; Var2 Dose Not Show Anything.. ConsoleWrite ('$Var2 : ' & $Var2 & @CRLF) Func _FileGet_RealName2($sFile) $sFile = StringRegExpReplace($sFile, "(?i).*[[:punct:]](\w*?)\..*", "$1") Return $sFile EndFunc #EndRegion #Region Mine.. #Include <String.Au3> $Var1 = _FileGet_RealName1 ('This..Is..A..Test.Au3') ; $Var = This..Is..A..Test ConsoleWrite ('$Var1 : ' & $Var1 & @CRLF) $Var2 = _FileGet_RealName1 ('Test..Au3') ; Var2 = Test. ConsoleWrite ('$Var2 : ' & $Var2 & @CRLF) Func _FileGet_RealName1 ($File) Local $String, $Return If StringInStr ($File, '.') = '0' Then Return $File ElseIf $File = '' Then Return $File EndIf $String = StringSplit ($File, '') For $Array = $String['0'] To '1' Step '-1' If $String[$Array] <> '.' Then $Return = $Return & $String[$Array] Else $Return = _StringReverse ($Return) $Return = '.' & $Return $Return = StringReplace ($File, $Return, '') ExitLoop EndIf Next Return $Return EndFunc #Region Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
GEOSoft Posted January 19, 2009 Share Posted January 19, 2009 Well since I won't use console write I tested it in MBs and it returned properly using "AutoIt..Is..FTW.Au3" But it did fail on "test..au3" I'll look at that later. I might have to test twice for the regexp. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Alek Posted January 19, 2009 Share Posted January 19, 2009 (edited) why not just Func _FileGetRealName($File) Return StringLeft($File, StringInStr($File, ".", True, -1) - 1) EndFunc Edited January 19, 2009 by Alek [font="Impact"]Never fear, I is here.[/font] Link to comment Share on other sites More sharing options...
ResNullius Posted January 19, 2009 Share Posted January 19, 2009 why not just Func _FileGetRealName($File) Return StringLeft($File, StringInStr($File, ".", True, -1) - 1) EndFuncClose Alek, but if the function is passed a file name without an extension, it wil return nothing. I use one like this: Func _FileGet_RealName($File) If StringInStr($File,".") then $File = StringLeft($File, StringInStr($File, ".", True, -1) - 1) Return $File EndFunc Link to comment Share on other sites More sharing options...
Spiff59 Posted January 19, 2009 Share Posted January 19, 2009 (edited) Might be more efficient to confine it to a single StringInStr statement... Func _FileGet_RealName($File) Local $x $x = StringInStr($File, ".", 2, -1) If $x Then $File = StringLeft($File, $x - 1) Return $File EndFunc Edited January 19, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
ResNullius Posted January 19, 2009 Share Posted January 19, 2009 Might be more efficient to confine it to a single StringInStr statement... Func _FileGet_RealName($File) Local $x $x = StringInStr($File, ".", 2, -1) If $x Then $File = StringLeft($File, $x - 1) Return $File EndFuncTrue. While were at it: Func _FileGet_RealName($File) Local $x = StringInStr($File, ".", 2, -1) If $x Then $File = StringLeft($File, $x - 1) Return $File EndFunc Link to comment Share on other sites More sharing options...
ptrex Posted January 20, 2009 Share Posted January 20, 2009 @all Why not ?! #include <file.au3> #include <array.au3> Dim $szDrive, $szDir, $szFName, $szExt $TestPath = _PathSplit(@ScriptFullPath, $szDrive, $szDir, $szFName, $szExt) _ArrayDisplay($TestPath,"Demo _PathSplit()") Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
WolfWorld Posted January 20, 2009 Share Posted January 20, 2009 @all Why not ?! #include <file.au3> #include <array.au3> Dim $szDrive, $szDir, $szFName, $szExt $TestPath = _PathSplit(@ScriptFullPath, $szDrive, $szDir, $szFName, $szExt) _ArrayDisplay($TestPath,"Demo _PathSplit()") Regards ptrex This will work but it's very slow! Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 20, 2009 Moderators Share Posted January 20, 2009 (edited) I'm so confused on the significance of this or what it's really trying to attempt other than removing the extension. StringRegExpReplace($s_file, "(.+?)(\.+(?:\w+\z|\z))", "$1") Works just fine for that. Edit: BTW, if you run this as the file name "This..Is..A..Test" Then you get a decimal as the last character with everyone elses example, I don't "think" that's the desired output is it? Having said that, this may be the desired outputStringRegExpReplace($s_file, "(.+?[^\.])(\.\w+\z)", "$1") Edited January 20, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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