kcvinu

How to get the name of the selected folder in explorer

20 posts in this topic

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)

 

Share this post


Link to post
Share on other sites



If you made the right-click entry in the registry using something like this

C:\my_cript.exe "%1"

Then you can get the info you want in your script compiled using $CmdLine[1]

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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)

 

Share this post


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
1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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
1 person likes this

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.

Share this post


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.

1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


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)

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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)

 

Share this post


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.
 

1 person likes this

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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)

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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
1 person likes this

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.

Share this post


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)

 

Share this post


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.

1 person likes this

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

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

Share this post


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)

 

Share this post


Link to post
Share on other sites

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.

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

  • Similar Content

    • jiggunjer
      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?
    • parrishjason
      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?
    • Skysnake
      By Skysnake
      Hi
      My new Win10 PC has decided that I am not allowed to create OpenOffice text or spreadsheet documents, but some other stuff I never use.  I would like advice on how to customize the "New" context(?) menu in the Windows Explorer "New" submenu.
      I attach a screenshot.
      Essentially, how do I customize that item? 
       

    • CrypticKiwi
      By CrypticKiwi
      Hello,
      i have a file containing a list of card names i want to send to internet explorer page.
      while sending it misses characters in the middle of the sent text.
      i decided to do a test to be sure and automate the process to detect the error,  so i send the text to explorer, copy it from explorer, save it in a file then read that file and compare it to the original list using stringinstr.
      here's a video of the error.
      Link
      Edit: you might want to turn down the sound ^
      is it a known issue? what can i do to resolve this issue?
      using windows 10, US keyboard...
    • Scottswan
      By Scottswan
      Basically I'm looking to make a snapshot of a whole HD's folders and files in one text file. Just the names. Preferably in alphabetical order.
      Folder 1
          File 1
          File 2
          File 3
      Folder 2
         Etc

      Is there a function that can copy just the names without opening the files? An alternative would be to put each into rename mode and then copy the text, but that is going to be painfully slow.
      Thanks.