Using the Windows Command Prompt to list all .jpg files in a directory

Using the Windows Command Prompt to list all .jpg
files in a directory and its subdirectories in a bare format, sorted by name. Here's the breakdown:
Command Breakdown
dir /b /s /A-D /o:gn *.jpg
Components:
1. dir
: Lists the contents of a directory.
2. /b
: Outputs the list in "bare" format, showing only file paths or names (no metadata like file size, date, or attributes).
3. /s
: Searches recursively through all subdirectories.
4. /A-D
: Lists only files, excluding directories (-D
).
5. /o:gn
: Sorts the output:
g
: Groups directories first (though not relevant here since only files are listed).n
: Sorts by name in ascending order.
6. *.jpg
: Filters the output to include only files with the .jpg
extension.
What It Does
The command will:
- Search for all
.jpg
files in the current directory and all subdirectories. - Output the results in a bare format, showing full file paths.
- Sort the results alphabetically by file name.
Example Output
If run in a directory like C:\Images
, the output might look like this:
C:\Images\photo1.jpg
C:\Images\photo2.jpg
C:\Images\subfolder\image1.jpg
C:\Images\subfolder\image2.jpg
Notes
1. Running in a Specific Directory:
- If you want to run this command in a specific directory (e.g.,
D:\Pictures
), change to that directory first:
cd D:\Pictures
Then run the command:
dir /b /s /A-D /o:gn *.jpg
2. Redirecting Output to a File:
- To save the output to a text file, use redirection:
dir /b /s /A-D /o:gn *.jpg > output.txt
This creates a file named output.txt
with the list of .jpg
files.
3. Filtering Other File Types:
- Replace
.jpg
with the desired file type (e.g.,.png
or.
for all files).
Let me know if you need further clarification or help!