Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyCharm File and Folder Operations

PyCharm File and Folder Operations

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

This section details operations such as creating, moving, renaming, and searching for files and folders.


1. Basic file and folder operations

1.1 Create a new file/folder

Method 1: Create via the right-click menu

  1. in Project tool window (Project View) Right-click the target directory in it

  2. Select:

  3. New -> Python File(Create .py file)

  4. New -> Directory(Create folder)

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

  6. -

    New -> Python File(Create .py file)

    -

    New -> Directory(Create folder)

    -

    Other file types (HTML, JSON, etc.)

    Method 2: Create via keyboard shortcut


    1.2 Rename files/folders

    Safe rename (recommended)

    1. Select the file -> right-click -> Refactor -> Rename

    2. Or use the keyboard shortcut:Shift + F6

    3. Enter new name → press Enter Confirm

    Advantage:

    Direct rename (not recommended)


    1.3 Move files/folders

    Safe move (recommended)

    1. Select the file -> right-click -> Refactor -> Move

    2. Or the shortcut:F6

    3. Select the target directory -> click Refactor

    effect:

    Drag-and-drop move (not recommended)


    1.4 Delete files/folders

    Safe delete

    1. Select the file -> right-click -> Refactor -> Safe Delete

    2. Or the shortcut:Alt + Delete

    3. PyCharm checks whether any code references the file -> confirm deletion

    Normal delete


    2. File content operations

    2.1 Quick navigation

    Operation Shortcut (Windows/Linux) Shortcut (Mac)
    Go to file Ctrl + Shift + N ⌘ + Shift + O
    Go to class Ctrl + N ⌘ + O
    Go 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)

    2. Supports regex, case matching, and file type filtering

    3. -

      Supports regex, case matching, and file type filtering

      1. 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 use Version control tools View file modification differences


      3. Advanced file management tips

      3.1 File templates

      Customize the default content when creating new files:

      1. Settings -> Editor -> File and Code Templates

      2. Choice Python 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 needed):

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

      2. Can restore versions from any point in time


      3.3 File markers

      -

      Add bookmarks:F11(line-level) / Ctrl + F11(with marker)

      -

      View bookmarks:Shift + F11


      4. Frequently asked questions

      Q1: How to hide specific files/folders?

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

      2. Or edit .idea/.gitignore

      Q2: How to batch rename files?

      1. Select multiple files -> Shift + F6

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

      Q3: How to recover accidentally deleted files?

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

      2. Find the pre-deletion version -> restore


      5. Quick reference table

      Operation Shortcut (Win/Linux) Shortcut (Mac)
      New file Alt + Insert ⌘N
      Rename Shift + F6 ⇧F6
      Move files F6 F6
      Safe delete Alt + Delete ⌘Delete
      Global search Ctrl + Shift + F ⌘ + Shift + F
      Go to file Ctrl + Shift + N ⌘ + Shift + O