scwoobles Posted August 31, 2016 Share Posted August 31, 2016 I am looking for a func that will let me find a folder name. if I tell the script where to look eg. C:\Programdata\microsoft, and to look for a folder called "Testxxxxx" where the xxxxxx = a random number and pull that back to a varible. how do I do that. I have looked through the help file and looked at google, I can't really find anything. Any help would be nice Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 1, 2016 Moderators Share Posted September 1, 2016 You must have missed _FileListToArray and _FileListToArrayRec in your searches. If you are looking for a folder in C:\Temp with some variation of "Testxxx" you would simply do this: #include <Array.au3> #include <File.au3> Local $aDirs = _FileListToArray("C:\Temp", "Test*", $FLTA_FOLDERS, True) If IsArray($aDirs) Then _ArrayDisplay($aDirs) Else ConsoleWrite("No folders matching the criteria found." & @CRLF) EndIf I'll leave you to look through the help file to see when you would use _FileListToArrayRec over _FileListToArray. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
scwoobles Posted September 1, 2016 Author Share Posted September 1, 2016 Thank You, But I always have trouble with array's I Just cant grasp them. But thank you this is what I am looking for. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 1, 2016 Moderators Share Posted September 1, 2016 12 minutes ago, scwoobles said: I always have trouble with array's I Just cant grasp them. Then you have a long, hard road ahead of you when it comes to scripting... "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
scwoobles Posted September 1, 2016 Author Share Posted September 1, 2016 I know, But I aint no quitter. Anyway ok I got that working and it displays fine but how would I split the string just to get the folder. so instead of C:\temp\test1234 I would just get the test1234 Link to comment Share on other sites More sharing options...
scwoobles Posted September 1, 2016 Author Share Posted September 1, 2016 string split into another array right Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 1, 2016 Moderators Share Posted September 1, 2016 No, you would read the help file Look at the last parameter for _FileListToArray "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
pluto41 Posted September 1, 2016 Share Posted September 1, 2016 #include <Array.au3> #include <File.au3> Local $aSplittedString Local $aDirs = _FileListToArray ( "C:\Temp", "Test*", $FLTA_FOLDERS, True ) If IsArray ( $aDirs ) Then _ArrayDisplay ( $aDirs ) ; Notice element [0] contains the number of matches For $i = 1 to $aDirs [0] ; For element 1 in the array to the element matches found in ( element [0] ) ConsoleWrite ( "Folder: " & $aDirs [$i] & @CRLF ) ; Write the full folder name path to the console window $aSplittedString = StringSplit ( $aDirs [$i], "\" ) ; Split the folder name into a new array, split character = '\'. ConsoleWrite ( "The part you wanted : " & $aSplittedString [ Ubound ($aSplittedString) -1 ] & @CRLF ) Next Else ConsoleWrite ( "No folders matching the criteria found." & @CRLF ) EndIf I suggest read: https://www.autoitscript.com/wiki/Arrays. Its very helpful Link to comment Share on other sites More sharing options...
scwoobles Posted September 1, 2016 Author Share Posted September 1, 2016 thanks pluto41, but JLogan3o13 helped me already, Give a man a fish and he eats for a day, Teach a man to fish and he eats for a lifetime. thanks anyways Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 1, 2016 Moderators Share Posted September 1, 2016 @pluto41 That is nothing more than a Rube Goldberg approach... "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
pluto41 Posted September 1, 2016 Share Posted September 1, 2016 @JLogan3o13 LOL, You are right. I wanted the topic starter to learn something about array's by referring to the AutoIT array Wiki (i hope he will read the provided link). In case of solution yes yours is much better Link to comment Share on other sites More sharing options...
argumentum Posted September 1, 2016 Share Posted September 1, 2016 (edited) #include <MsgBoxConstants.au3> MsgBox(0, @ScriptName, Example(), 60) Func Example() ; Assign a Local variable the search handle of all files in the current directory. Local $hSearch = FileFindFirstFile(@AppDataCommonDir & "\microsoft\test*") ; Check if the search was successful, if not display a message and return False. If $hSearch = -1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.") Return SetError(1, 0, "") EndIf ; Assign a Local variable the empty string which will contain the files names found. Local $sFileName = "", $iResult = 0 While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop FileClose($hSearch) Return SetError(0, 0, $sFileName) ; you're looking for 1 anywayz ; Display the file name. $iResult = MsgBox(BitOR($MB_SYSTEMMODAL, $MB_OKCANCEL), "", "File: " & $sFileName) If $iResult <> $IDOK Then ExitLoop ; If the user clicks on the cancel/close button. WEnd ; Close the search handle. FileClose($hSearch) Return SetError(2, 0, "") EndFunc ;==>Example ..am I too late to share this ? maybe now you can fish and catch oysters too Edited September 1, 2016 by argumentum forgot to FileClose($hSearch) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 1, 2016 Moderators Share Posted September 1, 2016 (edited) 8 minutes ago, argumentum said: ..am I too late to share this ? maybe now you can fish and catch oysters too From 8 lines to 25, 3 times as slow, and only returns the first folder that meets the criteria. How is this worthwhile to the OP? Edited September 1, 2016 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
argumentum Posted September 1, 2016 Share Posted September 1, 2016 2 minutes ago, JLogan3o13 said: and only returns the first folder that meets the criteria. How is this worthwhile to the OP? 17 hours ago, scwoobles said: I am looking for a func that will let me find a folder name. So I pasted the code. 1 hour ago, scwoobles said: I always have trouble with array's I Just cant grasp them So I pasted the code. So the OP could have done this without much knowing of anything, just reading the help file. I'm just showing another way. Hope not to have offended or mislead or in any way created a detrimental situation for anyone. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
AutoBert Posted September 1, 2016 Share Posted September 1, 2016 4 hours ago, scwoobles said: Anyway ok I got that working and it displays fine but how would I split the string just to get the folder. so instead of C:\temp\test1234 I would just get the test1234 The fastest (and as i think easiest) way is: $sFullPath= 'C:\temp\test1234'; I would just get the test1234 $iPos=StringInStr($sFullPath,'\',0,-1) $sLastFolder=StringMid($sFullPath,StringLen($sFullPath)-$iPos+1) ConsoleWrite($sLastFolder&@CRLF) Link to comment Share on other sites More sharing options...
scwoobles Posted September 1, 2016 Author Share Posted September 1, 2016 Ok so there is defiantly more than 1 way to skin a cat(not that I ever would), I do appreciate all the feedback it now lets me know that I have to read the help file 30 times over but thanks again everyone argumentum 1 Link to comment Share on other sites More sharing options...
AutoBert Posted September 1, 2016 Share Posted September 1, 2016 (edited) 2 hours ago, scwoobles said: I do appreciate all the feedback it now lets me know that I have to read the help file 30 times Reading helpfile is always a good idea, but also testing the examples in helpfile brings some more feedback to your brain. I use AutoIt since > 7 years and every day i read in helpfile at least once a day. Most i also test the example. Edited September 1, 2016 by AutoBert argumentum 1 Link to comment Share on other sites More sharing options...
argumentum Posted September 2, 2016 Share Posted September 2, 2016 1 hour ago, AutoBert said: I use AutoIt since > 7 years and every day i read in helpfile at least once a day. ..are you turning this into a religion ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
AutoBert Posted September 2, 2016 Share Posted September 2, 2016 (edited) 44 minutes ago, argumentum said: are you turning this into a religion no, but i am a old man. Only blond haircutters must new learn after pausing more as 1/2 hour. Some functions i don't need every day i have also the need to read about. And no some roses for @Jos and the other devs: AutoIt is the first windows language, where i understood the helpfile from the beginning. But maybe the dev's must write a tut who to use this helpfile, seems most people ignore it. But's the best i ever read. Edited September 2, 2016 by AutoBert argumentum 1 Link to comment Share on other sites More sharing options...
argumentum Posted September 2, 2016 Share Posted September 2, 2016 lol, you think your memory is bad @AutoBert. I've written programs that I forgot I did and wrote because, then again, forgot I wrote. Functions ? oh my oh my. But the way you wrote it left you open for that and I, in a jolly mode, had to post Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. 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