Search code examples
pycharm

Show current directory in the Project Tool Window


I would like to see the folders and files after changing directory (os.chdir) to some other location, outside my project. Is there a way to set this? In Spyder for example the Files tab is updated every time you cd.


Solution

  • In Spyder for example the Files tab is updated every time you cd.

    No, PyCharm doesn't have this functionality in the Project Tool Window.

    after changing directory (os.chdir)

    The question here is where do you execute os.chdir? The above mentioned Project Tool Window isn't the Terminal, the Console, nor the Editor window (or one of the Run/Debug windows). The Project Tool Window does work inherently as a File Watcher, meaning if you change (e.g. delete, create, rename) files the window refreshes automatically to reflect those changes.

    But the Project Tool Window is not meant to reflect Python code execution (which os.chdir is: a command in a running Python interpreter. Notice that the Project Tool Window is meant to work regardless of having a Python interpreter installed or running.)

    Is there a way to set this?

    The closest functionality PyCharm provides is configuring costum scopes and setting those as the View of the Project Tool Window. Choose Edit Scopes and if your aim is having a number of predefined locations the Scope Configuration Controls lets you set them beforehand.

    Other than that, PyCharm has chosen a philosophy that for a number of functionalities like the one you're asking about it's better using the Operating System's file viewer or listing files in the terminal.

    To configure a custom scope in the Project Tool window follow these steps

    1. Create the custom scope

    create the custom scope

    2. Set the custom scope as the View in the Project Tool Window

    set the custom scope as the view in the Project Tool Window