Opening at current file's path

Environment: -->

I have needed many times to open the file dialog at the current file's path so that I can select other files related to current file. For example, we will often be doing 'Find in Files' in MSDEV's Samples Directories or MFC Source Directories. Once some of those files are opened, we would also like to open the related H files or other View files etc. To do that, mostly we open the directory and files explicitly by file dialog. And we can face similar scenario in many other cases.

Instead of opening explicitly, the following simple macro helps to change the DevStudio's current directory to the active file's path and opens the file dialog. Maybe somebody has done this sort of thing before but I thought I could share this with others here.


Sub OpenAtActiveFilePath()
'DESCRIPTION: Sets the application's working directory to the active file's directory

Dim PathString
PathString = ActiveDocument.Path
PrintToOutputWindow "Before: " + Application.CurrentDirectory
Application.CurrentDirectory = PathString
ExecuteCommand "FileOpen"
PrintToOutputWindow "After: " + Application.CurrentDirectory
End Sub

Date Last Updated: February 3, 1999


Comments

  • file transfer help from u GurU's

    Posted by martin08ph on 02/15/2006 03:59am

    am new as VB .NET developer guys,need a syntax or code for me to copy files to other path.
    martin08ph@yahoo.com

    Reply
  • Win2k problem???

    Posted by Legacy on 10/02/2000 12:00am

    Originally posted by: Tom Saul

    Does this macro work for anyone under Win2K? I added some debugging code and it seems to do the correct dir changes, but the open dialog ignores the current dir and always uses the last load location.

    Reply
  • You can do this without a macro

    Posted by Legacy on 02/09/1999 12:00am

    Originally posted by: Kenneth Kasajian

    You can do this without a macro. Make the desired document current. To make MSDEV's current directory be where the currently opened document is, simply do a File / Save As but don't save -- just cancel. In other words, Hit Alt-F, A then Esc.
    Now you can do a file open (Alt-F, O) and you'll be in the right place.

    Reply
  • Modification so that macro still works even if no documents are open

    Posted by Legacy on 02/08/1999 12:00am

    Originally posted by: Tom Archer

    Mr. Raju's macro is very useful. Therefore, I added it to my "macro" toolbar and use it instead of
    the typical File Open button on the Standard toolbar. However, like anything else, when you get accustomed to
    something, you want to use it all the time. 
    
    

    Unfortunately, in its current incarnation, the macro will fail if you don't have an open document. Therefore, I made a very slight modification to have the macro display the File Open dialog using the application's current directory if no documents are open in Visual Studio. If there are any documents that are open, the original code is executed and the File Open dialog is displayed using the directory of the currently active document.

    Sub OpenCurrFolder()

    'DESCRIPTION: Sets the application's working directory
    ' to the active file's directory

    PrintToOutputWindow "Before: " + Application.CurrentDirectory

    Dim PathString

    if Application.Documents.Count > 0 then
    PathString = ActiveDocument.Path
    else
    PathString = ApplicationCurrentDirectory
    end if
    Application.CurrentDirectory = PathString

    PrintToOutputWindow "After: " + Application.CurrentDirectory

    ExecuteCommand "FileOpen"
    End Sub

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • On-demand Event Event Date: October 23, 2014 Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this webcast to learn why physical appliances are preferable to virtual backup appliances, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds