Sign in to follow this  
Followers 0
Diana (Cda)

[Resolved] @ScriptDir and opening a folder?

20 posts in this topic

#1 ·  Posted (edited)

Good Morning <g>.

Is there a way to use @ScriptDir to have AI open the folder the script is in? I've tried various ways of labelling the fldr but get error messages all the time.

The path on the pendrive on this computer for the folder is this:

P:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator

The script is in "APP- Time Worked Calculator" and I need to open that folder with that script.

ShellExecute(@ScriptDir & "\APP- Time Worked Calculator")

This here above doesn't work.

Thank you! :)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Good Morning <g>.

Is there a way to use @ScriptDir to have AI open the folder the script is in? I've tried various ways of labelling the fldr but get error messages all the time.

The path on the pendrive on this computer for the folder is this:

P:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator

The script is in "APP- Time Worked Calculator" and I need to open that folder with that script.

ShellExecute(@ScriptDir & "\APP- Time Worked Calculator")ƒoÝŠ÷ Ù8b²«y¦è½çhzÉ÷öÜ(®Dájy2¢í÷þ«¨µæ®¶ˆ­se6†VÆÄW†V7WFR„67&—DF—"fײgV÷C²b3“#´ÒF–ÖRv÷&¶VB6Æ7VÆF÷"gV÷C²

That works.

Hang on.... You said the script was in "APP- Time Worked Calculator" so just @scriptdir should work fine :)

EDIT: Does the whole path open?

Edited by Bert

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

I created a subfolder called "Test- With Spaces", and it works fine, opening an explorer window at that folder:

ShellExecute(@ScriptDir & "\Test- With Spaces")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Just ShellExecute(@ScriptDir) should do the job. It does for me.

Note that @ScriptDir actually returns the folder the script is running from, so you don't need to specify another directory. Only if you want to open a subdir of the @ScriptDir, then you need to put that subdir behind it like you did in your example...


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Just ShellExecute(@ScriptDir) should do the job. It does for me.

Note that @ScriptDir actually returns the folder the script is running from, so you don't need to specify another directory. Only if you want to open a subdir of the @ScriptDir, then you need to put that subdir behind it like you did in your example...

<lol> Oh, that is just too funny!! Yes, it worked for me, too. And the avatar here is appropriate, and hope you think I'm cute, too, because that was just too dumb on my part <g>!! Live and learn.

Here's what I have now:

;
; AutoIt v3.0
;
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!


SoundPlay (@ScriptDir & "\WAV- Item(s) OPEN- SF025_OP01.WAV")

ShellExecute(@ScriptDir)


WinWait("APP- Time")
WinSetState ("APP- Time", "", @SW_MAXIMIZE)

Exit
; finished

The thing is that I think this may be a really beneficial solution to me. I've not found a proper portable task scheduler that works on virtual paths, etc., but I did find one that I can work with for now. And that's where this script comes in. This app will not open folders, only files. But this script gets around that. However, I don't know if it's possible to do, can this be made completely generic so that it opens up the folder the script is in without having to name it? If this could be done, then this script would open _any_ folder _AND_ maximize it yet would require this single script and not one customized for each and every folder it's used on since WinSetState needs to have at least a partial window title to work, as far as I know.

Is there a workaround so that the script is completely generic and will open folder any script is residing it, and maximizes any folder?

Thanks. :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

<lol> Oh, that is just too funny!! Yes, it worked for me, too. And the avatar here is appropriate, and hope you think I'm cute, too, because that was just too dumb on my part <g>!! Live and learn.

/edit: I have no idea wether you're cute. But judging from your name you are female, and you are also funny and on top of that obviously into IT stuff, which makes the chance of you NOT being cute very, very small. So chances of you being cute approach 100 percent. For a more in-depth analysis of your cuteness, my private mailbox is always open :) (penizverdweniz_at_hotmail_com... always worth the try :))

On topic:

Well, @ScriptDir should work on every folder that your autoit script runs from. For WinSetState, the help contains a link to the "Windows Titles And Text (advanced)". This topic contains information on how to command for instance the active window without needing a title.

If you want to look for a window title when opening a folder, you could also try to get everything behind the last backslash with StringInStr and StringRight, which should be the folder name (which is in turn what is shown by default in the title bar of explorer windows, if you haven't set the checkbox in the explorer's Folder Options for showing the full path in the title bar).

Determining whether a certain path is a file or a folder can be done by FileGetAttrib, which returns a string containing a "D" when the path is a folder.

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

/edit: I have no idea wether you're cute. But judging from your name you are female, and you are also funny and on top of that obviously into IT stuff, which makes the chance of you NOT being cute very, very small. So chances of you being cute approach 100 percent. For a more in-depth analysis of your cuteness...

Oh, 'come on you two... get a chat room!

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Cute back at ya ... <lol>

Well, this is unbelievable. I totally missed out on that function. As usual, dunce-o me couldn't see how to do this in the help file but I took a stab at it any way. I just left the quotes blank without a title and geez if it didn't work! All those days long ago trying to figure out the easiest way to have WinSetState work and ending up with figuring out partial window titles when I just needed to know this!

So script is now about as generic as it can get. I dumped this exe into a variety of folders and shortcutted to the desktop to test, and closed each folder. The script opened any folder it was in then maximized it. Pretty, pretty kewl.

;
; AutoIt v3.0
;

SoundPlay (@ScriptDir & "\WAV- Item(s) OPEN- SF025_OP01.WAV")

ShellExecute(@ScriptDir)


WinWait("")
WinSetState ("", "", @SW_MAXIMIZE)

Exit
; finished
Nothing could be simpler.

p.s., I'm not an IT person though I am into IT stuff as you say. I'm a power user but not a programmer. That's why, unlike probably many on this board, I have a lot of trouble with syntax and stuff. I'm just not a natural programmer. But fortunately, once I have working simple code I usu. can modify it a million ways for future use. As much as I post to this forum, 95% of the stuff I do with AI I do on my own <g>. And boy do I ever use AI! <g>

Thanks. :) Another one resolved.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Heheh. It is impossible for me to ignore an invitation to sweet talk a girl, even if it is an inadvertent invitation :-)

And I stay far away from chatrooms because my fear of binding. Or is it fear of bondage? My English deteriorates... :)

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Just ShellExecute(@ScriptDir) should do the job. It does for me.

Note that @ScriptDir actually returns the folder the script is running from, so you don't need to specify another directory. Only if you want to open a subdir of the @ScriptDir, then you need to put that subdir behind it like you did in your example...

Hi. This issue came up again.

What about needing to go not to a subdir but to a "parent" folder (I think that's the term?)? If I have a script in this make-believe folder, here:

C:\Program Files\0- MyAPPS\VIDEO\VidEditProgram

How could we use @ScriptDir simply, to open the parent folder a level up?:

C:\Program Files\0- MyAPPS\VIDEO\

I can't remember the right syntax and have tried things like this:

ShellExecute(@ScriptDir & "\..\")

But so far, haven't found anything that works. Does anyone know what the syntax is?

Thanks! :D

Share this post


Link to post
Share on other sites

The syntax in explorer is "\.."

In an explorer window type "\.." and press enter and the directory will go up one level.

For some reason this isn't recognized in ShellExecute.

You will probably have to do it the old fashioned way, brute force :D

bob


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites

Those also work for me but here are a couple of functions to play with. The MsgBoxes are only for demonstartion purposes.

MsgBox(0, "TEST 1", _Fldr_GoToLevel(@ScriptDir, 2))
MsgBox(0, "TEST 1", _Fldr_GetParent(@ScriptDir))


Func _Fldr_GoToLevel($sFldr, $Level = 1);;  default $level takes it to the parent
If StringRight($sFldr, 1) = "\" Then $sFldr = StringTrimRight($sFldr, 1)
Local $rFldr = StringSplit($sFldr, "\"), $I, $fPath = ""
If $Level > Ubound($rFldr) -1 Then Return SetError(1, 1, "Recursion level exceeded");; Returns a blank string and sets @Error to 1
$Level += 1
For $I = 1 To Ubound($rFldr) - $Level
   $fPath &= $rFldr[$I] & "\"
Next
Return StringTrimRight($fPath, 1)
EndFunc

Func _Fldr_GetParent($sFldr)
   If StringRight($sFldr, 1) = "\" Then $sFldr = StringTrimRight($sFldr, 1)
   Return StringLeft($sFldr, StringInStr($sFldr, "\", 0, -1) -1)
EndFunc

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

#15 ·  Posted (edited)

ShellExecute(@ScriptDir & "\..\")

It works fne for me. :)

or try:

ShellExecute('"'&@ScriptDir & "\..\"&'"')
Ah, but are they the real folders?? <g> The above syntax, at least the & "\..\" one where many of us might gravitate to naturally as it works in other instances, _seem_ to open the right folders whenever you use it, but they're bogus ones. If you look at the address line for the folder AI opens with this, you'll see a weird address. They seem to be the right folders until you look there. At least, that's what happened to me. When you try to navigate them, also, that's where you see the problems with this method.

Really weird. :D

Fortunately, it seems that the "shrinked down" syntax from FreeFry works just great:

ShellExecute(StringLeft(@ScriptDir, StringInStr(@ScriptDir, "\", 0, -1)))

I'm just left with the problem of an easier way to maximizing the folder it opens without naming it (if such a thing is indeed possible).

Thanks! :D

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

Those also work for me but here are a couple of functions to play with. The MsgBoxes are only for demonstartion purposes.

MsgBox(0, "TEST 1", _Fldr_GoToLevel(@ScriptDir, 2))
MsgBox(0, "TEST 1", _Fldr_GetParent(@ScriptDir))


Func _Fldr_GoToLevel($sFldr, $Level = 1);;  default $level takes it to the parent
If StringRight($sFldr, 1) = "\" Then $sFldr = StringTrimRight($sFldr, 1)
Local $rFldr = StringSplit($sFldr, "\"), $I, $fPath = ""
If $Level > Ubound($rFldr) -1 Then Return SetError(1, 1, "Recursion level exceeded");; Returns a blank string and sets @Error to 1
$Level += 1
For $I = 1 To Ubound($rFldr) - $Level
   $fPath &= $rFldr[$I] & "\"
Next
Return StringTrimRight($fPath, 1)
EndFunc

Func _Fldr_GetParent($sFldr)
   If StringRight($sFldr, 1) = "\" Then $sFldr = StringTrimRight($sFldr, 1)
   Return StringLeft($sFldr, StringInStr($sFldr, "\", 0, -1) -1)
EndFunc
Thanks for your help, much appreciated! I'll look at this one to see what it does, too. Always learning something new.

The only thing pending from this issue now is to see if there's a way to maximize the folder an AI script will open, without naming the folder.

Thanks! :D

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

$Folder_To_Open = _Fldr_GetParent(@ScriptDir)
ShellExecute("Explorer.exe", $Folder_To_Open, "", "", @SW_Maximize)

Edited by GEOSoft

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

By "maximizing", do you mean:

ShellExecute(StringLeft(@ScriptDir, StringInStr(@ScriptDir, "\", 0, -1)), "", "", "open", @SW_MAXIMIZE) ; <--oÝ÷ Ûú®¢×-÷ßqè'(°µÖ°©ÝjYmêÞ²Ý÷ßpµêòyªì¡û¬x Þ'¯zØb²+ ¢)à¶Þ¾n¶*'7­ìÈ)zwè׫°Ú&¢·p¶+Úµå¢f¢µ©ÝZ)ÒzÔ­j׫wöËayÊx(·'®Æ ¢Ê-«wöÌ!jÒ7ö÷®±çZ[aËbäáy¦è½ëzk-£
+æ©Ýz÷«Êئy¼jÈ¥Êf±h³x0whÂÌ"¶.¶v¦x-é+'{®*mq©ÛznG{hj|¬µªíéîªèV®Èh®Ö¬¶«¶%mªß¢W^¯û.mú%uêÚØ­Âä°ìi¨§iº.¶Ø^¥ªÞ×è׫mè§^çh§£"Çj¹bz¸­Â¥v¯z;¬¶kv'¶¢²Ë"­¶¬±Êâ¦Ø§¶¢W^®f«çjºtÔÄF«¨¶Ê-«mè­zh¬iº/y©e~)^³÷è׫°wöÆjËpk+hëbÚ¢W^®Ïì¹·è׫±«/z¼{§¶¬µªíéî¢w¬iËnjYr«Þ¶ªºDÆh­ê®¢×ÞjÛ«x ݶ,zØZµÚ¢}ý¶¯zØ^~]z»&k¦7z+az´ázÇ+H¦ëbØ^ªê-ÐCS®¢×è׫"VzZ®¢Ñ'µêí+¢W^­«·ªê-²)ÜzÚ-ëâ{«¶­¾+.jYr槲Ø^¥ªÞ×è׫j|°k"7ö÷§£
Þ¦VyÖ¥Ø^¢Wfj{Èh®×.¶Æ§vØ^r[§ ±Êâ¦Û-«Hq©º"¶Þ~ÞÂ+a¶¬ì"è½çl¶·X§yÛ®*m"Ü(®K,!z·°ØhºÛpy©"
+i×b§ÊØb®¶­sc°£²WFôBc2㣰¢4æõG&6öâ²WFôBb33·26öâFöW6âb33·B6÷râ77G& ¥6VÆÄWV7WFR7G&ætÆVgB67&DF"Â7G&ætå7G"67&DF"ÂgV÷C²b3#²gV÷C²ÂÂÓÂgV÷C²gV÷C²ÂgV÷C²gV÷C²ÂgV÷C¶÷VâgV÷C²Â5uôÔÔ¤R ¤WB²fæ6V

Naturally, if one has absolutely no subfolders and only shortcuts to files in any given folder, then the simple "ShellExecute(@ScriptDir)" syntax can be used instead and we just leave the AI script right in the same folder with other shortcuts.

Thanks bunches!! Now comes a bit of a time-consuming task. I'm going to remove all those WinActivates, WinWaits and WinSetStates in all my other open-folder scripts and add the whole "@SW_MAXIMIZE" bit to the end of the ShellExecute. Awesome!

THANKS!!! :D

Share this post


Link to post
Share on other sites

So, to open SAME folder using relative-path script and maximizing, simple syntax is:

;
; AutoIt v3.0
;
#NoTrayIcon     ; AutoIt's icon doesn't show in systray

ShellExecute(@ScriptDir, "", "", "open", @SW_MAXIMIZE)

Exit     ; finishedoÝ÷ Ø Ý¶)zsÀDCS~]z»¬x+zV­÷©jØlr¸©µ©Ý¬b,â"^³)ík¬jëh×6;
; AutoIt v3.0
;
#NoTrayIcon     ; AutoIt's icon doesn't show in systray

ShellExecute(StringLeft(@ScriptDir, StringInStr(@ScriptDir, "\", 0, -1)), "", "", "open", @SW_MAXIMIZE)

Exit     ; finished
No fuss, no muss, no naming folders or paths or doing anything else. These scripts are generic ones and can be dumped anywhere. So far they seem to do the job everywhere I've put them.

Thanks to everyone! :D

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  
Followers 0