PyCharm File and Folder Operations

PyCharm provides powerful file management features that allow developers to efficiently organize project structures.

This section will detail operations such as creating, moving, renaming, and searching files and folders.


1. Basic File and Folder Operations

1.1 Creating New Files/Folders

Method 1: Create via Right-Click Menu

  1. InIn the Project tool window (Project View),right-click the target directory

  2. Select:

    • New → Python File(creates a.pyfile)

    • New → Directory(creates a folder)

    • Other file types (HTML, JSON, etc.)

Method 2: Create via Shortcut

  • New file:Alt + Insert(Windows/Linux) / ⌘N(Mac)

  • New directory: same operation as above, select 'Directory'


1.2 Renaming Files/Folders

Safe Rename (Recommended)

  1. Select the file → Right-click →Refactor → Rename

  2. Or use the shortcut:Shift + F6

  3. Enter the new name → PressEnterConfirm

Advantages:

  • Automatically updates all code that references the file

  • Avoids import errors caused by manual renaming

Direct Rename (Not Recommended)

  • Right-click →Rename(may break code references)


1.3 Moving Files/Folders

Safe Move (Recommended)

  1. Select the file → Right-click →Refactor → Move

  2. Or shortcut:F6

  3. Select the target directory → ClickRefactor

Effect:

  • Automatically fixes all import paths

  • For example: movingutils/helper.pytocore/under, allfrom utils.helper import xxxwill be automatically updated tofrom core.helper import xxx

Drag-and-Drop Move (Not Recommended)

  • Directly dragging files may cause import path errors


1.4 Deleting Files/Folders

Safe Delete

  1. Select the file → Right-click →Refactor → Safe Delete

  2. Or shortcut:Alt + Delete

  3. PyCharm will check whether any code references the file → Confirm deletion

Normal Delete

  • Right-click →Delete(does not check references)


2. File Content Operations

2.1 Quick Navigation

Operation Shortcut (Windows/Linux) Shortcut (Mac)
Jump to File Ctrl + Shift + N ⌘ + Shift + O
Jump to Class Ctrl + N ⌘ + O
Jump to Symbol (Method/Variable) Ctrl + Alt + Shift + N ⌘ + Option + O
Recently Opened Files Ctrl + E ⌘ + E

2.2 Code Search and Replace

Search within Project

  1. Global Search:Ctrl + Shift + F(Mac:⌘ + Shift + F)

    • Supports regular expressions, case matching, and file type filtering

  2. Search in Current File:Ctrl + F(Mac:⌘ + F)

Replace Operations

  1. Global Replace:Ctrl + Shift + R(Mac:⌘ + Shift + R)

  2. Replace in Current File:Ctrl + R(Mac:⌘ + R)


2.3 File Comparison

  1. Select two files → Right-click →Compare Files

  2. or useversion control toolsto view file modification differences


3. Advanced File Management Techniques

3.1 File Templates

Customize the default content when creating new files:

  1. Settings → Editor → File and Code Templates

  2. SelectPython Script, modify the template:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    """
    @Author: ${USER}
    @Date: ${DATE}
    @Description: 
    """
    
    def main():
        pass
    
    if __name__ == '__main__':
        main()


3.2 Local History

PyCharm automatically records file modification history (no Git required):

  1. Right-click the file →Local History → Show History

  2. You can restore versions from any point in time


3.3 File Marking

  • Bookmarks:

    • Add bookmark:F11(line-level)/Ctrl + F11(with mnemonic)

    • View bookmarks:Shift + F11

  • TODO Comments:

    will beTODO tool windowcentrally displayed in


4. Frequently Asked Questions

Q1: How do I hide specific files/folders?

  1. Right-click the file →Mark Directory as → Excluded

  2. or edit.idea/.gitignore

Q2: How do I batch rename files?

  1. Select multiple files →Shift + F6

  2. Use pattern replacement (e.g.,test_*.py → spec_*.py)

Q3: How do I restore accidentally deleted files?

  1. Right-click the project root directory →Local History → Show History

  2. Find the version before deletion → Restore


5. Quick Reference Table

Operation Shortcut (Win/Linux) Shortcut (Mac)
New File Alt + Insert ⌘N
Rename Shift + F6 ⇧F6
Move File F6 F6
Safe Delete Alt + Delete ⌘Delete
Global Search Ctrl + Shift + F ⌘ + Shift + F
Jump to File Ctrl + Shift + N ⌘ + Shift + O
Other Extensions