Jump to content

How to get the name of the selected folder in explorer


kcvinu
 Share

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

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

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 comment
Share on other sites

Hi 

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

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

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

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

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 comment
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
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

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 comment
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 comment
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 comment
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
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

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 comment
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 comment
Share on other sites

Hi 

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

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

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 comment
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 comment
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 comment
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 comment
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.
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

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 comment
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 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

×
×
  • Create New...