Jump to content

Help with finding a files path


 Share

Recommended Posts

Hello, I am very new to scripting but would like to write a script to start an application. I would like to search for the applicaton on the computer the script is run on to find its path and save it as a string that I can use to start the program.

Any help would be appreciated. Thanks.

Link to comment
Share on other sites

  • Moderators

nlucci45,

Welcome to the AutoIt forums. :)

_FileListToArrayRec will search a drive to find the file - DriveGetDrive will list the drives on the machine if you need to search them all. Give it a go and see how you get on - you know where we are if you run into difficulties. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OK, I went to the help for both _FileListToArrayRec  and  DriveGetDrive and ran the two example scripts. For the first one I get an array with all the files in the autoIt installation. I tried to search for my filename in the c: path but it didnt work.  

Remember Im incredibly new here and I am not looking for you guys/gals to do this for me. Just need a little more.

mikell - can you elaborate on your approach?

thanks in advance for the help...

Link to comment
Share on other sites

  • Moderators

nlucci45,

Running the _FileListToArrayRec example will of course return all the files in the AutoIt installation as that is what the example is supposed to do. ;)

What you need to do is use the filename you are searching for as the $sMask parameter - then you will only get that file returned - and you set the root of the drive as the $sFilePath parameter to search the whole thing. So your code would look something like this:

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

$sFileName = "AutoIt3.exe" ; Just as an example

$aDriveList = DriveGetDrive("ALL")

;_ArrayDisplay($aDriveList, "Drives", Default, 8) ; If you want to see what was returned

For $i = 1 To $aDriveList[0]

    ; Test if drive ready
    If DriveStatus($aDriveList[$i] & "\") = "READY" Then
        ; Announce which drive we are searching
        SplashTextOn("Searching", "Drive " & StringUpper($aDriveList[$i]), 300, 100)
        ; Now search
        $aList = _FileListToArrayRec(StringUpper($aDriveList[$i]) & "\", $sFileName, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
        ; Clear splash
        SplashOff()
        ; Display Result
        If IsArray($aList) Then
            _ArrayDisplay($aList, "Files on " & $aDriveList[$i], Default, 8) ; If you want to see what was returned
            ; No point in seaarching further
            ExitLoop
        Else
            MsgBox($MB_SYSTEMMODAL, "Drive " & $aDriveList[$i], "No files found")
        EndIf

    EndIf
Next

; Announce result
MsgBox($MB_SYSTEMMODAL, "Found", $sFileName & " found at " & $aList[1])
Please ask if anything is unclear. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba, That script does what I want. Thanks! I can take $aList[1] and use it as the path to open my exe. Now, next thing if your still out there. How do I save $aList[1] so that I don't have to look for it each time I run the program? Do I store it in a txt file and read it upon execution? If the string isnt there I run your script and find it, if it is there I use whats in the txt file?

Thanks so much. And I looked through the Help at all the UDF and macros and didn't find anything that would do what Melba's script does...

Link to comment
Share on other sites

  • Moderators

nlucci45,

 

How do I save $aList[1] so that I don't have to look for it each time I run the program?

I would use an ini file - look at the Ini* functions in the Help file and see if you can get something working. If not post the code you tried (see here how to do it) and we can see what was wrong. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

 I think  using MelbaFindFile() which is your script altered for my program to find the path and  IniWriteSection and IniRead will work great. I find the path. Save it in the ini and put it in the programs path. Each time my program is run it checks to see if the applications path has been stored, if so gets the data and uses it to start the exe. I think I will also check to see if the path stored exists. Just in case someone reinstalls the application I am starting with my program. I know with the SSD's coming down I have been doing a bit of that myself.

Thanks for the responses. Thanks Melba23 for the help. I have learned so much messing around with autoit that I am looking for other things to do with it. I have NO real coding experience. Its kind of addicting...

Edited by nlucci45
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...