Jump to content
Sign in to follow this  
DarkAngel

Get the path of a directory

Recommended Posts

DarkAngel

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:

Share this post


Link to post
Share on other sites
water

Please have a look at FileSelectFolder.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
DarkAngel

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:

Share this post


Link to post
Share on other sites
Country73

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

Share this post


Link to post
Share on other sites
Country73

You can also use that for folders.


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

Share this post


Link to post
Share on other sites
DarkAngel

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?

Share this post


Link to post
Share on other sites
DarkAngel

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?

Share this post


Link to post
Share on other sites
Country73

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

Share this post


Link to post
Share on other sites
DarkAngel

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:

Share this post


Link to post
Share on other sites
Fatum48

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

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
Fatum48

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

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
DarkAngel

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:

Share this post


Link to post
Share on other sites
GEOSoft

$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!"

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
Sign in to follow this  

×