CMD Command Snippets
Useful Windows Command Line utilities for file management
📂 Finding Files
Search for files recursively
dir /s /b *keyword*.*
Find all PDFs in current dir and subdirs
dir /s /b *.pdf
Locate all .txt files from current location
where /r . *.txt
📋 Copying Files
Copy all JPGs to backup folder
for %F in (*.jpg) do copy "%F" backup\
Copy folder with subdirectories
xcopy /s /e source_folder dest_folder\
Fast copy (multithreaded)
robocopy source dest /E /MT:8
✏️ Renaming Files
Change file extension
ren *.txt *.bak
Add prefix to filenames
for %F in (*.pdf) do ren "%F" "prefix_%F"
🗑️ Deleting Files
Delete temp files quietly
del /q *.tmp
Delete matching files
for %F in (*old*.pdf) do del "%F"
Delete folder and contents
rmdir /s /q folder_name
🗂️ Organizing Files
Sort files by extension into folders
for %F in (*.*) do md "%~xF" 2>nul & move "%F" "%~xF\"
Move PDFs with certain string to folder
for %F in (*keyword*.pdf) do move "%F" target_folder\
⚙️ Batch Operations
List files to text file
for %F in (*.pdf) do echo "%F" >> filelist.txt
Delete .log files recursively
for /r %F in (*.log) do del "%F"
Delete files smaller than 1KB
for %F in (*) do if %~zF LSS 1024 del "%F"
🔧 Useful Combinations
Export PDF list to file
dir /b /s *.pdf > pdf_list.txt
Hide all text files
attrib +h *.txt
Unhide all text files
attrib -h *.txt