Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 06:00:44 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Get current directory  (Read 19547 times)

Hawkbane

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
IDEA: Get current directory
« on: July 17, 2005, 01:39:57 PM »
I am running Windows XP Pro with Blackbox as my default shell. I wouldl like a way to be able to map my PF4 key to open a DOS command prompt in the current directory that I am in, as in Linux.  I have the hotkeys plugin, and I can map it to open cmd.exe, but I can't find a way to get the current dir to pass it as an argument.  Would it be possible to code an app that would do that for me?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,412
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Get current directory
« Reply #1 on: July 17, 2005, 11:33:23 PM »
there are some addons to do this (right+click -> open dos box here) - though thats not really a hotkey.
it would be interesting to hear if anyone has an ideas of how to get the current directory in explorer; if so a macro tool or autoit might be able to do this.

many of us, including myself, use a windows explorer replacement which has buttons for things like "open dos box here" so that we don't need addons and stuff.  the existence of such buttons is one of the major reasons people use a file explorer replacement like powerdesk or directory opus.

Hawkbane

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
Re: IDEA: Get current directory
« Reply #2 on: July 18, 2005, 06:57:11 AM »
I use an Explorer replacement as well, the free version of Xplorer2, and I do know about the context menu option Microsoft add on for 'open command prompt here'.  What I initially tried was copying the registry value of the context menu item into a shortcut, then passing the command prompt that shortcut as a value.  That works ... kind of.   It will get the context of the dir that the shortcut is in, not update and get the one where I currently am. 

I have asked around on several forums about this before, and have done a fair bit of searching throughout the Web.  General concensus is that everyone thinks it is possible, but no one knows how :) .  Hope one of you can help me.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,412
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Get current directory
« Reply #3 on: July 18, 2005, 08:07:59 AM »
you could definitely achieve this easily with directory opus (but beware the price of dir. opus).
it will let you assign a hotkey to any button, so you could easily add a hotkey to the "command prompt here" button, which is what you are wanting.  does xpolorer2 maybe let you do this also?

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
DONEISH: Get current directory
« Reply #4 on: July 18, 2005, 12:54:38 PM »
 :) Here's a quick hack to solve the problem. It works in Explorer, but I don't know about Blakcbox.

OpenOther
Select files or folders in Explorer, press Ctrl-Enter to open the files in the programs you define below using extensions.

Download and install AutoHotKey from www.autohotkey.com. Save the script as OpenOther.ahk and doubleclick to run.

Skrommel


;OpenOther
;Select files or folders in Explorer, press Ctrl-Enter
; to open the files in the programs you define below using extensions.
;Skrommel @2005


;Extensions
;extension=command          Place a ` before commas
directory=cmd /k cd        ;Program to open directories
unknown=                   ;Program to open unknown or undefined extensions
empty=Notepad              ;Program to open files without extensions
txt=Write                  ;Program to open .txt-files
wri=Write
dll=Notepad
                           ;Add your own extensions here


;Program
^Enter::                   ;Hotkey Ctrl-Enter
Clipboard=
Send,^c
ClipWait,1
Loop,Parse,Clipboard,`n,`r
{
  SplitPath,A_LoopField,name,dir,ext,name_no_ext,drive
  FileGetAttrib,attrib,%A_LoopField%
  StringGetPos,dir,attrib,D
  If dir=0
    Run,%directory% %A_LoopField%
  Else
  {
    If ext=
      Run,%empty% %A_LoopField%
    Else
    {
      command:=%ext%
      If command<>
        Run,%command% %A_LoopField%
      Else
        If unknown<>
          Run,%unknown% %A_LoopField%
    }
  }
}
Return
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
« Last Edit: July 20, 2005, 11:26:39 AM by skrommel »

Hawkbane

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
Re: IDEA: Get current directory
« Reply #5 on: July 20, 2005, 12:50:42 PM »
Skrommel, thanx for the code and the suggestion.  My question is, how is this different than 'Open Command Prompt here' other than the hot key?  You still have to have the folder selected, correct?  That really isn't what I am looking for.  In Linux, if you have Konquerer (KDE version of Explorer/IE) open, then hit PF4, then the terminal shell opens in that current directory, no selection of the current dir is necessary.  I assume that it just "pings" the tree and the return directory is passed to the terminal as a variable.

Everything that I have seen with Windows shows me that I have to physically select the folder that I want to open to pass to the cmd.  A.K.A., I need to back up to the parent dir of the folder that I want, highlight the folder, then apply whichever means I desire to open the cmd.  I don't think that this should have to be.  From my thinking, there HAS to be a way in which for this to work.  It just needs to be figured out :) .  Do I make what I am looking for clear?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,412
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Get current directory
« Reply #6 on: July 20, 2005, 04:26:22 PM »
a reasonable compromise might be to modify it so that you can select any FILE and hit the hotkey to bring up a dos command box in the directory where the file lives - you'd still have to select something, but you wouldnt have to go up to the parent folder first so it would save some time.

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
DONE: Get current directory
« Reply #7 on: July 21, 2005, 06:02:04 AM »
 :) Again, this is for Explorer:

GetCurDir opens the current dir of Explorer in a command prompt when pressing Ctrl-D. No selection nessesary, and the window can be in the background.

To use it: Turn on the setting to show the entire path in the title bar of Explorer. I haven't got an english version, but it's something like Tools-Folder options-Show complete path in titlebar.

Edit: Updated to v1.0: Added detection of ordinary Explorer windows, the kind without the treeview. The other kind has priority, though.

Also, some of the pathless folders like My Computer wont show up.

Download and install AutoHotKey from www.autohotkey.com. Save the script as OpenOther.ahk and doubleclick to run.

Skrommel


;GetCurDir.ahk v1.0
;Open the current dir of Explorer in a command prompt by pressing Ctrl-D
;Skrommel @2005

^d::
SetKeyDelay,0
IfWinExist,ahk_class ExploreWClass
  WinGetTitle,title,ahk_class ExploreWClass
Else
  WinGetTitle,title,ahk_class CabinetWClass
Run,cmd /k cd %title%
SplitPath,title,,,,,drive
WinActivate,ahk_class ConsoleWindowClass
WinWaitActive,ahk_class ConsoleWindowClass
Send,%drive%{Enter}cls{Enter}
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
« Last Edit: July 21, 2005, 08:13:56 AM by skrommel »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,412
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Get current directory
« Reply #8 on: July 21, 2005, 06:32:28 AM »
awesome -
skrommel, may i make a suggestion: adding a version # to the comments at the top of your scripts would make it easier for people to make sure they always had latest version.

murple

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 23
    • View Profile
    • Donate to Member
Re: IDEA: Get current directory
« Reply #9 on: January 10, 2007, 06:42:08 PM »
Skrommel,

I realise this thread is ancient but I've been roaming the forums and this caught my eye. I read through your code and couldn't figure out why you had to send text to the command prompt. It's odd you can't just do run, cmd f:\anydrive\anyfolder. Anyhow, I found a nice article at microsoft.com which says: "You can use multiple commands separated by the command separator && for string, but you must enclose them in quotation marks (for example, "command&&command&&command")." which means we can use:

SplitPath,title,,,,,drive
run, cmd /k "%drive%&&cd %title%"[/


Full script:
;GetCurDir.ahk v1.0
;Open the current dir of Explorer in a command prompt by pressing Ctrl-D
;Skrommel @2005

^d::
SetKeyDelay,0
IfWinExist,ahk_class ExploreWClass
  WinGetTitle,title,ahk_class ExploreWClass
Else
  WinGetTitle,title,ahk_class CabinetWClass
SplitPath,title,,,,,drive
run, cmd /k "%drive%&&cd %title%"

See also this great utility: The Command Prompt Explorer Bar

murple

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 23
    • View Profile
    • Donate to Member
Re: IDEA: Get current directory
« Reply #10 on: January 10, 2007, 06:43:38 PM »
Oh, I forgot to mention that I like your script(s).  :Thmbsup:

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Get current directory
« Reply #11 on: January 16, 2007, 01:23:52 PM »
 :tellme: I never knew you could use the &&... Great, murple!

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

murple

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 23
    • View Profile
    • Donate to Member
Re: IDEA: Get current directory
« Reply #12 on: February 08, 2007, 06:42:44 PM »
Neither did I, I learned it while trying to decipher your code. Glad you liked it. :D

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,286
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Get current directory
« Reply #13 on: March 13, 2009, 06:26:17 PM »
I found a function by gafrost called _WinGetPath() on AutoIt3 forum that gets
the path of whatever launched the active window without using the window title.
I used it to create an AutoIt3 app that listens for Shift-NumberPadMinus hotkey
and opens the "home folder" of the active window.

Because it uses WMI I think it's only usable on XP and later.
I call it, imaginatively enough, Home Folder.  :)
Here's the page:
http://www.favessoft.com/hotkeys.html

Seems like it may come in pretty handy. I know I hate opening
shortcuts just to get the Location info(even hovering the mouse
is kind of a pita.)

(It doesn't open a command prompt, but at least in Vista if you
shift-right click in the folder you get the Open Command Window Here.)
« Last Edit: March 13, 2009, 06:28:16 PM by MilesAhead »

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,258
    • View Profile
    • Coding Snacks by Lanux128
    • Read more about this member.
    • Donate to Member
Re: IDEA: Get current directory
« Reply #14 on: March 13, 2009, 08:38:40 PM »
that's a nice one there.. check out this post for a similar but mouse-initiated script. :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,286
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Get current directory
« Reply #15 on: March 13, 2009, 09:02:11 PM »
that's a nice one there.. check out this post for a similar but mouse-initiated script. :)

That's cool.  I'm thinking esp. since XP doesn't have the built-in Command Prompt thingie like Vista maybe I'll add another hotkey to open one in that folder.  I'll give it a go.

Edit: I updated to 1.1  With this version, additional hotkey Control-NumberPadMinus opens a command prompt.  If the active window is an application window the "home folder" of that app is the current directory.  If it's an explorer folder, that folder should be the current directory for the command prompt.  Seems good on Vista.  I haven't tried it on XP yet though.


« Last Edit: March 13, 2009, 09:57:55 PM by MilesAhead »

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,845
    • View Profile
    • Donate to Member
Re: IDEA: Get current directory
« Reply #16 on: March 14, 2009, 12:26:39 AM »
Nice thread!

I looked for GetCurDir (or something similar) on Skrommel's 1 HOUR SOFTWARE and didn't succeed at locating anything.

If indeed there isn't anything comparable there, may be it's worth placing GetCurDir on the page :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,286
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Get current directory
« Reply #17 on: March 14, 2009, 12:40:12 AM »
The thread made me curious and when I saw the function in AutoIt3 to get the path from the active window I wanted to see if it worked.  I'm starting to like doing these small gizmos.  I sweat blood doing this dumb application launcher thing that I've had on SoftPedia for a couple of years.  I got as many downloads in about 2 months with a program that just opens and closes the optical drive tray!!  Guess there is something to the idea of keeping it simple. :)

Edit: oh yeah, I wanted to mention I updated to version 1.2.  It now calls a function to reduce the memory footprint if running on Win2k or newer. Task manager was showing it around 6 MB on Vista64.  Now shows it < 4 MB.

Home Folder 1.2
« Last Edit: March 14, 2009, 12:45:09 AM by MilesAhead »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,286
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Get current directory
« Reply #18 on: March 15, 2009, 11:41:59 AM »
I added a wrinkle to Home Folder 1.3.  If you have FavesSA 4.6 or later running with Monitor enabled and press Alt-NumberPadMinus while an application window is active, the complete program path is sent to FavesSA.  If it's not already in the current list, it's added.

I don't know how Windows decides to stick programs in its start menu mru list but it seems like there's no rhyme or reason I can figure out.  This gives manual control to add to the FavesSA list.