Forum Discussion

almmatt's avatar
almmatt
Contributor
9 years ago

Check folder path in Explorer window

I have read in the community it can be difficult to automate Windows Explorer due to different operating systems. My task is to use an operation in my application to locate a file or folder on disk using a menu option. This would open Windows Explorer to the directory where the folder or file exists. Is there a way to validate this reliably across all operating systems?

  • You can try this. It uses the FindChild method to look within all Sys process which will include all Explorer processes.

     

    SUB TestSol2
      DIM tst, PropNames, PropValues
      ' Creates arrays of property names and values
      PropArray = Array("Name", "Visible")
      ValuesArray = Array("Window('*', 'Music', 1)", "True")  'This will change with folder name we are looking for
      
      SET tst = Sys.FindChild(PropArray, ValuesArray, 10)
      IF tst.Exists THEN
        Log.Message("The folder was found open in exlporer")
      ELSE
        Log.Error("The folder was not found open in exlporer")
      END IF
      Delay(1000)
    END SUB
  • djadhav's avatar
    djadhav
    Regular Contributor

    If you're just trying to open the windows explorer to a location that you know already, you can use this:

     

    Sub Test1
      Dim explorer
      Dim dlgRun
      'Simulates pressing Win + R button i.e. Open the run dialog
      Call NameMapping.Sys.Keys("[Hold][Win]r[Release]")
      Set explorer = Aliases.explorer
      Set dlgRun = explorer.dlgRun
      'Here we set the text to the location we want to open
      Call dlgRun.ComboBox.SetText("C:\Users\djadhav\Music\Dance")
      dlgRun.btnOK.ClickButton
      'The windows explorer opens to the above location
    End Sub
    • almmatt's avatar
      almmatt
      Contributor

      I am using a function within our application that opens Windows Explorer, my goal is to write a script that will verify that the explorer window that was opened is the correct path.

      • djadhav's avatar
        djadhav
        Regular Contributor

        You could use this:

         

         tst = Sys.Process("explorer").Window("*", "Music", 1).Exists

        where "Music" can be replaced with the name of the folder that you're trying to detect.

        tst = True means the explorer is open to the correct folder

        tst = False means it is not