How to Copy All MP4 Files to Current Directory Using Windows CMD

If you’ve ever faced the task of aggregating all MP4 files from various subfolders into a single directory, you know how tedious it can be to do it manually. In this guide, we’ll walk through a simple one-liner command that accomplishes this task efficiently using the Windows Command Prompt.

Requirements

  • A Windows operating system
  • Basic familiarity with the Command Prompt

Steps

  1. Open Command Prompt:
    • Navigate to the Start Menu, search for cmd, and open the Command Prompt.
  2. Navigate to the Target Directory:
    • Use the cd command to change the directory to where you’d like to copy the MP4 files. For example,

    cd C:\Users\YourUsername\TargetDirectory

  3. Run the One-Liner Command:
    • Copy and paste the following command into the Command Prompt and press Enter.

    for /r %i in (*.mp4) do copy "%i" .

Explanation

  • for /r: This part of the command recursively scans through all the subdirectories of the current directory.
  • %i: A temporary variable that holds the full path of each MP4 file found during the scan.
  • in (*.mp4): The command looks specifically for files with an .mp4 extension.
  • do copy "%i" .: For each file found, the copy command is executed to copy the file into the current directory.

Key Points to Remember

  • Recursion: The /r flag is crucial for searching through subdirectories.
  • File Filtering: The (*.mp4) part ensures you’re only looking for .mp4 files.
  • Copy Operation: The copy command is used to duplicate the files into your current directory.

Note: Be cautious of duplicate filenames. If a file with the same name exists in the destination directory, it will not be overwritten, but you’ll receive a prompt to decide what to do next.