vocoder Posted February 28, 2007 Posted February 28, 2007 so lets say i have a file called myfile_02272007_text.txt is there anyway to get the 02272007 part? basically i want to a scan a directory for any file that begins with myfile_ and ends with _text.txt - and then get the number in the middle....if the number in the middle is greater than the previous one i have saved, process it. but i have no idea how to do this, or if it is even possible?
Moderators SmOke_N Posted February 28, 2007 Moderators Posted February 28, 2007 Look at _PathSplit if you are getting the entire path... Then or look at _StringBetween(). 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.
Moderators SmOke_N Posted February 28, 2007 Moderators Posted February 28, 2007 stringsplit() would work very well also.That would work yes... or even :$sString = 'myfile_02272007_text.txt' $aNum = StringRegExp($sString, '.*?(\d+)', 1) If IsArray($aNum) Then MsgBox(0, '', $aNum[0]) 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.
MrCreatoR Posted February 28, 2007 Posted February 28, 2007 (edited) Try this function: #include <Array.au3> $Ret = _StringStripNotNum('myfile_02272007_text.txt') MsgBox(0, "", $Ret) $RetArr = _StringStripNotNum('myfile_02272007_text.txt', 1) _ArrayDisplay($RetArr, "_StringStripNotNum Demo") Func _StringStripNotNum($String, $RetType=0) $String = StringRegExpReplace($String, '[^0-9]', '') If $RetType = 1 Then Return StringSplit ($String, "") Return $String EndFunc Edited February 28, 2007 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
WeMartiansAreFriendly Posted February 28, 2007 Posted February 28, 2007 i would like too add to this ;Harder way $file = 'myfile_02272007_text.txt' $myfile = StringLeft($file,StringInStr($file,'_')) $number = StringTrimRight( StringMid($file,StringInStr($file,'_')+1), StringInStr($file,'_',-1) +2) $text = StringRight($file,StringInStr($file,'_')+2) msgbox(0,'Harder',$myfile&@LF&$number&@LF&$text) ;Easier way $file = 'myfile_02272007_text.txt' $split = StringSplit($file,'_') If Not @error Then msgbox(0,'Easy',$split[1]&'_' &@lf& $split[2] &@lf& '_'&$split[3]) Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
vocoder Posted March 2, 2007 Author Posted March 2, 2007 thanks. now what if I don't know the name of the file, other than my and text....so i will never know the number 02272007, is there a wildcard function or something $file = "my_*_text.txt"; ?
MrCreatoR Posted March 2, 2007 Posted March 2, 2007 (edited) $String = "my_*_text.txt" MsgBox(0, "", _GetMidleString($String, "_", "_")) Func _GetMidleString($String, $DelimStart="_", $DelimEnd="_") Local $FirstPos = StringInStr($String, $DelimStart) Local $MidleStr = StringTrimLeft($String, $FirstPos) Local $SecondPos = StringInStr($MidleStr, $DelimEnd) + $FirstPos Return StringTrimRight(StringTrimLeft($String, $FirstPos), (StringLen($String) - $SecondPos + 1)) EndFunc Edited March 2, 2007 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Moderators SmOke_N Posted March 2, 2007 Moderators Posted March 2, 2007 I seriously don't know why this has gone past the StringRegExp(). $sString = 'myfile_02272007_text.txt' $aNum = StringRegExp($sString, '_(\d+)_', 1) If IsArray($aNum) Then MsgBox(0, '', $aNum[0]) 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.
lod3n Posted March 2, 2007 Posted March 2, 2007 Because regex makes newbs cry. [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]
PaulIA Posted March 2, 2007 Posted March 2, 2007 I have file/path functions in the Auto3Lib Strings module that might be helpful: _Str_ChangeFileExt - Changes the extension of a filename _Str_ExtractFile - Extracts the name part of the given filename _Str_ExtractFileName - Extracts the name and extension parts of the given filename _Str_ExtractFilePath - Extracts the drive and directory parts of the given filename Auto3Lib: A library of over 1200 functions for AutoIt
Moderators SmOke_N Posted March 2, 2007 Moderators Posted March 2, 2007 Because regex makes newbs cry. ... I couldn't stop chuckling!! 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.
MrCreatoR Posted March 3, 2007 Posted March 3, 2007 SmOke_N $sString = 'myfile_02272007_text.txt' $aNum = StringRegExp($sString, '_(\d+)_', 1) If IsArray($aNum) Then MsgBox(0, '', $aNum[0]) This is just for numbers, and what if the midle string is not numbers? Maby this help: $sString = 'myfile_02272007_text.txt' MsgBox(0, "", _StringMidle($sString, "_", "_")) Func _StringMidle($String, $Start, $End) $Start = StringRegExpReplace ($Start, '([\+\|\*\^\$\.\[\]\(\)\?\\])', '\\\1') $End = StringRegExpReplace ($End, '([\+\|\*\^\$\.\[\]\(\)\?\\])', '\\\1') Local $pattern = '^[^' & $Start & ']*' & $Start & '([^' & $End & ']*)' & $End & '.*$' Return StringRegExpReplace($String, $pattern, '\1') EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Moderators SmOke_N Posted March 3, 2007 Moderators Posted March 3, 2007 SmOke_NThis is just for numbers, and what if the midle string is not numbers?basically i want to a scan a directory for any file that begins with myfile_ and ends with _text.txt - and then get the number in the middle.... 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.
MrCreatoR Posted March 3, 2007 Posted March 3, 2007 Because this:is there a wildcard function or something$file = "my_*_text.txt";I am assuming that he want the string that between the _ characters .vocoderMaby you tell as, what realy do you need? to find a number between these characters, or unknown string that can be there instead of 02272007? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
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