How to Loop a Command Prompt

How to Loop a Command Prompt thumbnail
Learn command line looping.

Have you ever needed to repeat a command in the command prompt window, but weren't sure how to make the command prompt perform a loop? The Windows command prompt is a useful tool that dates back to the days before Windows Explorer and the Windows user interface that we know today. The DOS language allows us to move between directories, and launch and delete files. Learn how to move several files into a different directory by creating a loop in the command line window with one command line entry.

Instructions

  1. Create Test Environment

    • 1

      Create a folder on your desktop named "Test."

    • 2

      Open the Test folder and add a new folder named "Move."

    • 3

      Right-click in the Test folder window. Click "New" and "Text Document."

    • 4

      Rename the new text document "pic1.jpg." Click "Yes" when asked if you want to change the file extension name.

    • 5

      Create four additional new text documents and name them "pic2.jpg," "pic3.jpg," "pic4.jpg" and "pic5.jpg." Again, click "Yes" when asked if you want to change the file extension name.

    Create a Command Prompt Loop

    • 6

      Open the command prompt window by clicking the Start button, "All Programs," "Accessories" and "Command Prompt."

    • 7

      Type the following command into the command prompt window:

      for /f %%a IN ('dir /b *.jpg') do move c:\users\<username>\desktop\test\*.jpg "c:\users\<username>\desktop\test\move"

      Be sure to type in your username where you see the "<username>" placeholder above.

    • 8

      Press "Enter." Notice that all of your files have moved into the "Move" folder.

Related Searches:

References

  • Photo Credit Stockbyte/Stockbyte/Getty Images

Comments

You May Also Like

Related Ads

Featured