Jump to content

How to get the name of the selected folder in explorer


Recommended Posts

Hi there,

I am planning to make script for hide/show folders in windows explorer. This is the pseudo code

1. User selectes a folder in windows explorer

2. In the right click context menu, he can see an option named "Hide this folder"

3. If he chooses that option, then my script starts working

4. First, it will collect the full path and name of the folder.

5. Then it will change the file attrib with the FileSetAttrib() function.

I don't know how to do the step 4. Please help. Thanks in advance

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

Hi 

mikell, can you please suggest me some examples or tutorials about it. ?

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

Ok you can try this small example

I did it on XP so it may be a little different on an other OS

Registry key to add :

[HKEY_CLASSES_ROOT\Directory\shell\my_script\command]
@="C:\\my_script.exe \"%1\""

Use the code below to make a compiled script named  "my_script.exe" and put this exe in C:

#include <GUIConstantsEx.au3>

GuiCreate("", 500, 30, -1, 30)
GuiCtrlCreateInput($CmdLine[1], 10, 5, 480, 20)
GuisetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE
  Sleep(10)
Wend
Link to post
Share on other sites
  • Moderators

I wrote code to do this ... trying to remember where ... I believe it was in a thread by guiness but didn't really adapt to what he was trying to accomplish.

I'm only giving the above clues in case I can't find it and someone feels like spending a day or two looking for it :) ...

Edit:

Found the thread, but it's not exactly what I wrote the code for:

Thread: '?do=embed' frameborder='0' data-embedContent>>

My Code: page-2#entry1042451'>page-2#entry1042451

Mine opens the explorer with the files you want before hand selected, not what you're currently selecting, however that seems quite fairly easy, maybe follow through and see how it's being done in the code above.

Edited by SmOke_N

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.

Link to post
Share on other sites

@kcvinu - I would add to what the others wrote, by advising caution when working with the registry ... you should always backup keys and sections before making changes, especially when new to it.

Like SmOke_N I was also looking for some functions I wrote a while back, that add or remove entries for the three main things.

[1] Folder - folders and zip files.

[2] Directory - Folders.

[3] * - Files

My functions were also designed to work with shortcuts/command-line so that one could include them as part of an uninstall routine.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to post
Share on other sites

Hi,

Thank you all. Let me read more. By thae way, Is there any functions to get the folder name instead of FileOpenDialoge. Like a FolderOpenDialoge ?. Because i want to get only the foldername. 

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

Hi 

mikell,

I can understand that $CmdLine[1] is an array. But where is the declaration and initialization code of that array ?. 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

FileSelectFolder - Help file

$Cmdline is an array that you get automatically when a script starts...from the Help file

 

Command Line Parameters

Passing command line parameters to your own executable is achievable in AutoIt. Passed commandline parameters can be viewed by using the constant variables $CmdLine and $CmdLineRaw. Assigning these variables with new data will cause AutoIt to return an error, as these cannot be changed during the script's execution. Note that both variables exist whether commandline parameters are passed or not.

The special array $CmdLine is initialized at the start of the script with the command line parameters passed to your AutoIt script. If running your script instead of the executable, then the ScriptName.au3 willl be ignored as a parameter.
 

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to post
Share on other sites

kcvinu, Did you try the Automating Windows Explorer UDF? It's rather simple:

 

#include "Includes\AutomatingWindowsExplorer.au3"

Opt( "MustDeclareVars", 1 )

Example()

Func Example()
  ; Windows Explorer on XP, Vista, 7, 8
  Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
  If Not $hExplorer Then
    MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." )
    Return
  EndIf

  ; Get an IShellBrowser interface
  GetIShellBrowser( $hExplorer )
  If Not IsObj( $oIShellBrowser ) Then
    MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." )
    Return
  EndIf

  ; Get other interfaces
  GetShellInterfaces()

  ; Get current folder
  Local $pFolder = GetCurrentFolder(), $sFolder
  SHGetPathFromIDList( $pFolder, $sFolder )
  MsgBox( 0, "Folder", $sFolder )

  ; Free memory
  _WinAPI_CoTaskMemFree( $pFolder )
EndFunc

Windows Explorer should be open before you run the example.

The example shows the current folder. Use GetFolders() to get selected folders.

Edited by LarsJ
Link to post
Share on other sites

Hi 

LarsJ, I am studying it now. It is a great udf. But i can't understand some lines from that UDF.

for example, in this code; 

; Windows Explorer on XP, Vista, 7, 8
$hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
If Not $hExplorer Then Exit

; Shell object
$oShell = ObjCreate( "Shell.Application" )

; Find window
For $oWindow In $oShell.Windows()
  If $oWindow.HWND() = $hExplorer Then ExitLoop
Next

; Selected items

For $oItem In $oWindow.Document.SelectedItems()
    Global $strArray = StringSplit($oItem.path(),"\")
Next
Local $int = UBound($strArray)
Local $out = $strArray[$int-1]
MsgBox(0,"",$out & @CRLF & $oItem.Path())

can you explain the 2nd line ?. Especially the "^" symbol. And in 6th line, what is Shell.Application ? And i can see a $oShell.Window. Is there any more items with $oShell. how can i see it ?. For example, in VB.NET, i can easily see all the stuff related to an object with intelliscense. Is it possible in autoit ?

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites
  • Moderators

Line 2 is a regular expression search for the class of the explorer window.  "^" is the beginning of the string search, "$" is end of the string.

Also, lines 9 - 11 are redundant, they do nothing, and line 16 makes no sense being in a for loop without it itself being an array.

Edited by SmOke_N

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.

Link to post
Share on other sites

Hi 

SmOke_N, line 16 is my contribution. I need to get the filename or folder name from $oItem.Path()

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

kcvinu, The first 11 lines (the rest of the lines seems to be yours) in the code in post 12 are not really part of my UDF. These lines just shows how you can get the selected items in Windows Explorer with shell objects.

What I'm doing is, that I create these objects with ObjCreateInterface. But you don't have to understand all that in details to use the UDF.

"Shell.Application" is the string you use to create the proper shell object. And how can you know, that you have to use exactly this string. You can't. You have to read the MicroSoft documentation for shell objects.

There are probably more methods and properties for the $oShell object. You have to read the documentation.

I'm not using Scite, but I think there are some kind of intelliscense in Scite. I don't know how much information you'll get for shell objects, or other objects. Just read the documentation.

SmOke_N, It's correct that lines 9 - 11 are redundant, if there is only one Windows Explorer open. If two or more Windows Explorer are open at the same time, this loop finds the window object, that matches the $hExplorer handle. Since it's not possible to know how many Windows Explorer are open, you need the loop.

Link to post
Share on other sites
  • Moderators

@LarsJ, doesn't matter if there are more than window explorer's open.  There's no condition for your statement if it is true other than exiting the loop.  Therefore it's completely redundant.

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.

Link to post
Share on other sites

SmOke_N, You are wrong. You need the proper $oWindow object in line 15. This is the $oWindow object you have, when the loop exits:

If $oWindow.HWND() = $hExplorer Then ExitLoop

Edited by LarsJ
Link to post
Share on other sites

Hi 

LarsJ, Thank you for pointing me to the right direction. Actually, i haven't tried your UDF yet. But i think i need to try it first. Anyhow, this code is working but i would like to learn more about your UDF. Thanks for that amazing UDF. Need to learn MS documentation. I will sure inform you after trying your UDF with the above example.

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites
  • Moderators

Understood, I didn't realize you were using $oWindow later on in the script.  Thanks

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.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Synaps3
      This script will make it so you can press Alt + "+" in Windows Explorer to select all files with the current file extension. This is something that I wanted for a long time and it should be a feature in Windows, but it's not. The only way to get close is to use the search thing (but then it shows the results excluding everything else) or to group by that type, but I don't want it grouped.
      You can press Alt + Enter right after to open properties on those files or you can press delete to delete only files of that type.
      You need the "Automating Windows Explorer" pack here: https://www.autoitscript.com/forum/topic/162905-automating-windows-explorer/
       
      #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) HotKeySet("!=", "SelectTypes") Func SelectTypes() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle("[REGEXPCLASS:^(Cabinet|Explore)WClass$]") If Not $hExplorer Then MsgBox(0, "Explorer", "Could not find Windows Explorer.") Return EndIf $hExplorer = WinActive("[REGEXPCLASS:^(Cabinet|Explore)WClass$]") If Not $hExplorer Then MsgBox(0, "Explorer", "Windows Explorer is not in focus.") Return EndIf ; Get an IShellBrowser interface GetIShellBrowser($hExplorer) If Not IsObj($oIShellBrowser) Then MsgBox(0, "Explorer", "Could not get an IShellBrowser interface.") Return EndIf ; Get other interfaces GetShellInterfaces() ; Get selected files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aAllFiles = GetItems(False, False) Local $aFiles = GetItems(True, False) Local $sExt Local $i If UBound($aFiles) = 1 Then ;MsgBox(0, "Selected", $aFiles[0]) $sExt = StringRight($aFiles[0], StringLen($aFiles[0]) - StringInStr($aFiles[0], ".", 0, -1)) ;MsgBox(0, "Selected", $sExt) For $i = 0 To UBound($aAllFiles) - 1 If StringInStr($aAllFiles[$i], ".") > 0 Then If StringRight($aAllFiles[$i], StringLen($aAllFiles[$i]) - StringInStr($aAllFiles[$i], ".", 0, -1)) = $sExt Then SetSelectedItem($i) EndIf EndIf Next Else MsgBox($MB_ICONWARNING, "Error", "None or multiple items selected!") EndIf EndFunc While 1 GUIGetMsg() Wend  
    • By WoodGrain
      Hi All,
      Trying to open windows explorer to a WebDav location and it's not working quite how I want, on the computers it is setup as a "network location" (as opposed to a "mapped drive", and this unfortunately can't be changed), the "Data" WebDav folder sits directly under "This PC" if that's an easier way to get to it. any suggestions as to what I can correct to get the 2nd example to work?
      ; This works, but I'm trying to avoid this as users normally see the URL style in the 2nd example below $folderToOpen = "\\mycompany.sharepoint.com@SSL\DavWWWRoot\Data" Run("Explorer.exe " & $folderToOpen) ; This does not work, it tries to open the WebDav url in the default web browser $folderToOpen = "https://mycompany.sharepoint.com/Data" Run("Explorer.exe " & $folderToOpen) ShellExecute also opens it in the default browser.
      Saw _WinAPI_ShellOpenFolderAndSelectItems but couldn't get the 2nd example to work.
      If I manually open Windows Explorer and paste in https://mycompany.sharepoint.com/Data it loads the WebDav directory without issue.
      If I have to use the pathing from the first example it is fine, just trying to give users a familiar experience.
      Thanks!
    • By Pintu
      Good evening guys,
      i'm having a problem, not about the code (i'm only thinking about it at the moment) but about the way i can do it.
      I have a webpage (photo N.1) it has some elements in it.
      I need only the table (photo N.2), looking at the code and with _IEFunctions i can easy find the table but how i can i "copy" it?
      As i said it's really easy to found with a script but what should i do then? Copy the source? And how can i display it to the user?
      In my head i'd like to display it inside a GUI, is that possible?
       
      Thanks in advance
       
      Edit: Posted 2 times same photo. Now should be OK

       

    • By jiggunjer
      I want to listen for certain windows events like window open/closed. After reading the help I think I need to use ObjCreate('shell.application') and ObjEvent with that object to create/register a listener. The problem is I don't know what interface or events (i.e. the specific event names) are available for the listener. I tried searching MSDN but it is a labyrinth and I'm not that familiar with the programming frameworks/models used by Windows, and all the examples seem to refer to compiled code using .NET or some other api.
      Can any1 point me in the right direction? Also is using COM objects considered the 'modern' way to do this, or should I be using some other framework/resources?
    • By parrishjason
      I want an AutoIT script to be able to open a given page, but also be able to check the HTTP status of the page and print out the status code in a message box. Looking through some of the documentation, I've found how to open a page in Internet Explorer and keep it as an object by doing this:
      $IE = _IECreate($google_url)
      ^^^ but how would I find the HTTP status 200 from here?
×
×
  • Create New...