Jump to content

Get the path of a directory


Recommended Posts

the FileOpenDialog is used to get the path of a certain file with the help of a gui . i want to get the path of a "folder" in a similar way using a GUI similar to that of FileopenDialog . How do i do that ? Please help . :blink:

Link to comment
Share on other sites

Please have a look at FileSelectFolder.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Please have a look at FileSelectFolder.

Geez thanks .. i didnt read the help file carefully.. by the way whats the way of hiding and renaming folders in autoit? Te filesetattrib function is applicable for files but i couldnt figure out how to set attributes of a folder when i have the path of that folder. The dirmove can be used to rename the folder i guess cause if the folder in the destination is same then it is renamed instead of being replaced. PLease help :blink:

Link to comment
Share on other sites

Geez thanks .. i didnt read the help file carefully.. by the way whats the way of hiding and renaming folders in autoit? Te filesetattrib function is applicable for files but i couldnt figure out how to set attributes of a folder when i have the path of that folder. The dirmove can be used to rename the folder i guess cause if the folder in the destination is same then it is renamed instead of being replaced. PLease help :blink:

In the Help File, search for File.

You'll see all of the functions associated with File.

Look at the "FileGetAttrib" and "FileSetAttrib"

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

You can also use that for folders.

I tried but nothings happening .. i have worked with files using that command . Isnt a problem ,but i cant do that with directories. The script works all right but the folders arent hidden. I tried doing that by DOS using _rundos .. But i think all commands of dos doesnt work properly in this way. Can you please write that part of code which u say can be used to set attributes to a directory?

Link to comment
Share on other sites

You can also use that for folders.

I tried but nothings happening .. i have worked with files using that command . Isnt a problem ,but i cant do that with directories. The script works all right but the folders arent hidden. I tried doing that by DOS using _rundos .. But i think all commands of dos doesnt work properly in this way. Can you please write that part of code which u say can be used to set attributes to a directory?

Link to comment
Share on other sites

I just ran this, from inside of Scite.

ConsoleWrite(FileGetAttrib("C:\Temp\test") & @CRLF)
FileSetAttrib("C:\Temp\test","+H")
ConsoleWrite(FileGetAttrib("C:\Temp\test") & @CRLF)

The first response I got was: D

Then it set the "Hidden" Attribute

Then the final response was: HD

I checked "C:\Temp\test" and it was hidden.

Hope that helps.

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

I just ran this, from inside of Scite.

ConsoleWrite(FileGetAttrib("C:\Temp\test") & @CRLF)
FileSetAttrib("C:\Temp\test","+H")
ConsoleWrite(FileGetAttrib("C:\Temp\test") & @CRLF)

The first response I got was: D

Then it set the "Hidden" Attribute

Then the final response was: HD

I checked "C:\Temp\test" and it was hidden.

Hope that helps.

I didnt do the consolewrite stuff.. newaz. lemme check out..i will let you know . Thanks a lot :blink:

Link to comment
Share on other sites

I didn't used the GUI of AutoIt yet ... But if you can assign the following code to a button it might work

To test it you can just load it in AutoIt and press F5 to see if it suit your needs.

This code is to select a folder and not a file.

$oShell = ObjCreate("Shell.Application")
$oFolder = $oShell.BrowseForFolder(0,"Select Folder",0,0)
$sFolderPath = $oFolder.Items.Item.Path
MsgBox(0,"",$sFolderPath)

Of course you can after then remove the MsgBox and display the value of $sFolderPath anywhere you like.

Hope it helped!

Alex

Link to comment
Share on other sites

I didn't used the GUI of AutoIt yet ... But if you can assign the following code to a button it might work

To test it you can just load it in AutoIt and press F5 to see if it suit your needs.

This code is to select a folder and not a file.

$oShell = ObjCreate("Shell.Application")
$oFolder = $oShell.BrowseForFolder(0,"Select Folder",0,0)
$sFolderPath = $oFolder.Items.Item.Path
MsgBox(0,"",$sFolderPath)

Of course you can after then remove the MsgBox and display the value of $sFolderPath anywhere you like.

Hope it helped!

Alex

As already pointed out, the correct functionality is already provided within AutoIt. There is no need to use a COM object at all for this simple task.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

As already pointed out, the correct functionality is already provided within AutoIt. There is no need to use a COM object at all for this simple task.

Ok maybe my mistake but I'm curious to see what is the code behind FileSelectFolder! I'm not a HUGE coder but I think there's might be some lines in that code that looks similar to what I wrote. Cause the parameters of FileSelectFolder are kind of similar/Identical to any VB code.

Ok my code didn't handle on which button the user click cause it was just an example.

No offense I was just trying to help...

Link to comment
Share on other sites

No offense taken. Your method might be similar to the way it's done in VB (it is) but AutoIt is written in C++ using the Windows API and that bears no similarity to VB.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Well dun laugh guys but i still couldn't filesetattrib to set attributes for folder. I figured out that the filegetfolder function gives the full path of the folder. now if i assign that to a variable and use the filesetatrib on it to set atributes then its kinda not possible to set attributes to the full path of the folder. Can the path be navigated into and just the folder name be obtained in any way ? :blink:

Link to comment
Share on other sites

$sFolder = StringRegExpReplace($sPath, "^.+\\(.+)(?:\\)$", "$1");; allows for a trailing backslash if one exists

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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