scwoobles

Unsure how to find the right path

21 posts in this topic

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

Share this post


Link to post
Share on other sites



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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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...


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

string split into another array right

Share this post


Link to post
Share on other sites

No, you would read the help file :) Look at the last parameter for _FileListToArray


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
#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 :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@pluto41 That is nothing more than a Rube Goldberg approach...


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

@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 ;)

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 by argumentum
forgot to FileClose($hSearch)

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

 

Share this post


Link to post
Share on other sites

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

1 person likes this

Share this post


Link to post
Share on other sites

#17 ·  Posted (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 by AutoBert
1 person likes this

Share this post


Link to post
Share on other sites

#19 ·  Posted (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 by AutoBert
1 person likes this

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now