Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming a file in PyCharm

Tags:

python

pycharm

In PyCharm 3.4, I want to rename a file on the file tree that appears on the left of the IDE. If I right-click on a file, there is an option to delete it, but not to rename it. Similarly, there is no way of renaming it from the File or Edit menus. Is there a fundamental reason why PyCharm does not allow this from within the IDE, or have I missed the correct way of doing it?

like image 644
Karnivaurus Avatar asked Oct 19 '14 19:10

Karnivaurus


People also ask

How do I rename an existing file in Python?

rename() method allows you to rename files in Python. When used with the os. listdir() method, you can use os. rename() to rename all the files in a folder.

How do I rename a file in IDE?

Files and Directories can be renamed by clicking on an already-selected item in the Project tool and editing the name in place. When Enter is pressed to complete the edit, the item will be renamed on disk.


2 Answers

Renaming files in PyCharm is simple. You simply select Refactor > Rename when right-clicking on a file in the tree.

This will open a popup where you can type in the new filename. There are additional options when renaming, such as searching for references and in comments, strings, etc.

NOTE: While PyCharm is indexing files, the option is unavailable. Once indexing is finished (can take a while), it becomes available again (thanks @Eric_Sven_Puudist).

like image 60
Ffisegydd Avatar answered Sep 21 '22 05:09

Ffisegydd


You can just choose the file and hit shift+F6 rename it then hit refactor

like image 21
Padraic Cunningham Avatar answered Sep 23 '22 05:09

Padraic Cunningham