 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Mon Mar 01, 2010 11:18 am Post subject: SetWorkingDir, Current one |
|
|
I need to add to the top of my script something like that
SetWorkingDir, Current Dir
No idea how, any idea? |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 01, 2010 11:21 am Post subject: Re: SetWorkingDir, Current one |
|
|
"Current Dir" would be the working dir (& running a command for that would be pointless), so perhaps you mean...
| Code: | | SetWorkingDir, %A_ScriptDir% |
|
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Mon Mar 01, 2010 11:26 am Post subject: |
|
|
I get your point, but no, as silly as it sounds I want the Working Dir to be the active/open one, I found a script on the forum to delete empty folders but it needs specified working dir, that's why I asked
Here is the script I found
| Code: | SetWorkingDir,
$MinimumSplashTime=850
SplashImage,, W258 B2 ,,Building directory list...
$SplashStartTime=%A_TickCount%
Sleep 10 ;-- Allow splash image to render
$DirectoryList=
Loop *.*,2,1
$DirectoryList=%$DirectoryList%%A_LoopFileFullPath%`r`n
Sort $DirectoryList
$SplashElapsedTime:=A_TickCount - $SplashStartTime
if $SplashElapsedTime<%$MinimumSplashTime%
{
$SleepTime:=$MinimumSplashTime - $SplashElapsedTime
Sleep %$SleepTime%
}
SplashImage,, W354 B2 ,,Searching for directories to delete...
$SplashStartTime=%A_TickCount%
$DeleteTotal=0
$LoopCount=0
Loop 99
{
$LoopCount:=$LoopCount + 1
$DeleteCount=0
Loop parse,$DirectoryList,`n,`r
{
if A_LoopField= ;-- Ignore blank item
continue
IfExist %A_LoopField%
{
FileRemoveDir %A_LoopField%
if errorlevel=0
$DeleteCount:=$DeleteCount + 1
}
}
$DeleteTotal:=$DeleteTotal + $DeleteCount
If $DeleteCount=0
break
}
$SplashElapsedTime:=A_TickCount - $SplashStartTime
if $SplashElapsedTime<%$MinimumSplashTime%
{
$SleepTime:=$MinimumSplashTime - $SplashElapsedTime
Sleep %$SleepTime%
}
SplashImage off
ExitApp |
|
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Mon Mar 01, 2010 11:33 am Post subject: |
|
|
| Don't know how, sorry |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 01, 2010 11:35 am Post subject: |
|
|
| Gauss wrote: | | ...I want the Working Dir to be the active/open one... |
...the one in the currently active Explorer window? That's completely different.
I'm pretty sure there are scripts on the forum for getting the currently active explorer window's path...but before I try to write that, do you want that or the currently selected file's paths? I think getting the currently selected files/dirs paths is easier/more reliable than getting the current explorer window's path... |
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Mon Mar 01, 2010 11:39 am Post subject: |
|
|
I want it to work in the current/open Dir and its sub folders
I already have a way to retrieve that, but combining these 2 together is giving me a headache
Here is how I get the current path:
| Code: | Strip( _String )
{
StringReplace, _String, _String, `r`n, , All
StringReplace, _String, _String, `r, , All
StringReplace, _String, _String, `n, , All
_String = %_String%
Return, _String
}
ifwinexist, ahk_class CabinetWClass
{
ControlGetText, OutputVar, toolbarwindow322, ahk_class CabinetWClass
stringreplace, address, OutputVar, Address:
address := Strip( address )
MsgBox, %address%
} |
|
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Mon Mar 01, 2010 11:52 am Post subject: |
|
|
Did you read the splitpath documentations, it is very easy, just use the variables you need and skip the ones you don't, you want a folder just use something like this
| Code: | Strip = c:\my documents\user1\this is a\test\folder\file.ahk
SplitPath, strip, , OutDir
MsgBox % OutDir |
_________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 01, 2010 11:53 am Post subject: |
|
|
Replace...
...with...
| Code: | | SetWorkingDir, %address% |
...but note, like I said, that may not be reliable, since when My Documents is the current window the path ends up being "My Documents" which is not a full/real path...
Also, this is a weird way to do it...
| Code: | ControlGetText, OutputVar, toolbarwindow322, ahk_class CabinetWClass
stringreplace, address, OutputVar, Address: |
...why get the path from toolbarwindow322 & then need to clean "Address:" out of it?...(I understand if it's just code you found, but it's still weird)...I'd use...
| Code: | if (WinExist("ahk_class CabinetWClass")) {
ControlGetText, path, Edit1
path:=Strip(path)
SetWorkingDir, %path%
} |
...also I'm not sure "path:=Strip(path)" is necessary, but I left it in... |
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Mon Mar 01, 2010 12:00 pm Post subject: |
|
|
Yours didn't work to get current path, it returned empty
Maybe your not using W7?!
I believe my way is not the best to get the current path, but it works
BTW.. SetWorkingDir, %path% doesn't work |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 01, 2010 12:11 pm Post subject: |
|
|
| Gauss wrote: | | Maybe your not using W7?! |
...lol nope, XP here...you didn't specify...can you open window spy & point at the address bar?...& tell me the class name?
| Gauss wrote: | ...but it works  |
...on Win7, that is...on mine, toolbarwindow322 is the links toolbar...lol...
| Gauss wrote: | | BTW.. SetWorkingDir, %path% doesn't work |
...that's only supposed to work if my code gets the path into the path var...in your orig code it uses OutputVar as one var & address as another var, I just replaced both with a path var...
Also, since I'm curious, did you get your computer with Win7 or get it with Vista & upgrade to Win7?...soon I may need to upgrade a computer from Vista to Win7 & need to know how to do it without losing files n stuff... |
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Mon Mar 01, 2010 12:26 pm Post subject: |
|
|
Ok, I finally got it to work my way
Here is how:
| Code: | Strip( _String )
{
StringReplace, _String, _String, `r`n, , All
StringReplace, _String, _String, `r, , All
StringReplace, _String, _String, `n, , All
_String = %_String%
Return, _String
}
ifwinexist, ahk_class CabinetWClass
{
ControlGetText, OutputVar, toolbarwindow322, ahk_class CabinetWClass
stringreplace, address, OutputVar, Address:
address := Strip( address )
SetWorkingDir, %address%
}
$DirectoryList=
Loop *.*,2,1
$DirectoryList=%$DirectoryList%%A_LoopFileFullPath%`r`n
Sort $DirectoryList
$DeleteTotal=0
$LoopCount=0
Loop 99
{
$LoopCount:=$LoopCount + 1
$DeleteCount=0
Loop parse,$DirectoryList,`n,`r
{
if A_LoopField= ;-- Ignore blank item
continue
IfExist %A_LoopField%
{
FileRemoveDir %A_LoopField%
if errorlevel=0
$DeleteCount:=$DeleteCount + 1
}
}
$DeleteTotal:=$DeleteTotal + $DeleteCount
If $DeleteCount=0
break
}
Return |
| Quote: | | can you open window spy & point at the address bar?...& tell me the class name? |
As for upgrading I never recommend it, I fix computers all the time, never upgraded, always format and fresh windows installation, better. It is alot of work installing programs all over again, but its not something you do everyday. |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 01, 2010 1:05 pm Post subject: |
|
|
| Gauss wrote: | | Here is how: |
...that's exactly what I meant when I said "Replace...MsgBox, %address%...with...SetWorkingDir, %address%"...
...in that case my "ControlGetText, path, Edit1" should've worked...go figure... |
|
| Back to top |
|
 |
Gauss
Joined: 10 Sep 2009 Posts: 203
|
Posted: Mon Mar 01, 2010 1:15 pm Post subject: |
|
|
I wish it did my friend, it just doesn't, first it gives error about
And when deleting that part, MsgBox returns empty
I love small scripts so I would loved to use your way since its much smaller.
Maybe it has to do with W7? |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 01, 2010 2:01 pm Post subject: |
|
|
| Gauss wrote: | | ...first it gives error about... |
...missing function error? I was using the strip function you already posted, I just didn't re-post it in that post...
| Gauss wrote: | And when deleting that part, MsgBox returns empty  |
...OK, plz try this...
| Code: | #NoEnv
Explorer_win:="ahk_class CabinetWClass"
Explorer_ctrl:="Edit1"
F9::
ControlGetText, path, %Explorer_ctrl%, %Explorer_win%
if (errorlevel) {
if (WinExist(Explorer_win)) {
WinGet, Explorer_ctrllist, ControlList
WinGetText, Explorer_text
msgbox, 16, , Error: ControlGetText failed`n`nControl not found (%Explorer_ctrl%)...`n`n---Control List---`n%Explorer_ctrllist%`n---Window Text---`n%Explorer_text%---end---
} else {
msgbox, 16, , Error: ControlGetText failed`n`nNo Explorer window found...`n`n%Explorer_win%
}
return
}
msgbox, 64, , Success!`n`npath(%path%)
return |
...run that, open an explorer window & press F9...if you get a msgbox with alot of info, press Ctrl+C & paste here... |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|