AutoHotkey Community

It is currently May 27th, 2012, 4:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: March 1st, 2010, 12:18 pm 
Offline

Joined: September 10th, 2009, 5:54 pm
Posts: 203
I need to add to the top of my script something like that

SetWorkingDir, Current Dir

No idea how, any idea?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 1st, 2010, 12:21 pm 
"Current Dir" would be the working dir (& running a command for that would be pointless), so perhaps you mean...

Code:
SetWorkingDir, %A_ScriptDir%


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 12:26 pm 
Offline

Joined: September 10th, 2009, 5:54 pm
Posts: 203
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 12:31 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Use splitpath to find the current directory and use that where you need it.

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 12:33 pm 
Offline

Joined: September 10th, 2009, 5:54 pm
Posts: 203
Don't know how, sorry


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 12:35 pm 
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...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 12:39 pm 
Offline

Joined: September 10th, 2009, 5:54 pm
Posts: 203
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%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 12:52 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 12:53 pm 
Replace...
Code:
   MsgBox, %address%

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 1:00 pm 
Offline

Joined: September 10th, 2009, 5:54 pm
Posts: 203
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 :D

BTW.. SetWorkingDir, %path% doesn't work


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 1:11 pm 
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 :D

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 1:26 pm 
Offline

Joined: September 10th, 2009, 5:54 pm
Posts: 203
Ok, I finally got it to work my way :D

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?

Code:
Edit1


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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 2:05 pm 
Gauss wrote:
Here is how:

...that's exactly what I meant when I said "Replace...MsgBox, %address%...with...SetWorkingDir, %address%"...

Gauss wrote:
Code:
Edit1

...in that case my "ControlGetText, path, Edit1" should've worked...go figure...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 2:15 pm 
Offline

Joined: September 10th, 2009, 5:54 pm
Posts: 203
Quote:
go figure...


I wish it did my friend, it just doesn't, first it gives error about
Code:
path:=Strip(path)

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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 3:01 pm 
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...


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Mickers, rbrtryn, Yahoo [Bot] and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group