Windows 如何用where找檔案
在 Windows 11 中,where 是用來搜尋檔案路徑的命令。它支援遞迴搜尋、環境變數、顯示檔案大小與修改時間等功能。以下是完整參數說明與範例組合。
where [/r <Dir>] [/q] [/f] [/t] [$<ENV>:|<Path>:]<Pattern>[...]
| 參數 | 說明 |
|---|---|
/r <Dir> |
從指定目錄開始,遞迴搜尋所有子目錄 |
/q |
不顯示結果,只回傳 退出碼(0=找到,1=未找到) |
/f |
將結果用 引號括起來(方便處理含空格路徑) |
/t |
顯示檔案的 大小與最後修改時間 |
$<ENV>:<Pattern> |
使用環境變數指定搜尋路徑,例如 $PATH:notepad.exe |
<Path>:<Pattern> |
指定目錄搜尋,例如 C:\Windows:notepad.exe |
* / ? |
支援萬用字元,例如 *.txt 或 file?.exe |
/? |
顯示說明文件 |
where notepad.exe
→ 搜尋 notepad.exe 是否存在於目前目錄或 PATH 中。
where /r C:\ test.txt
→ 在 C:\ 及其所有子目錄中搜尋 test.txt。
where /t *.log
→ 顯示所有 .log 檔案的路徑、大小與修改時間。
where /f "My File.txt"
→ 顯示 "C:\Users\Juiwen\Documents\My File.txt"(加引號)。
where /q config.ini
echo %errorlevel%
→ 若找到則 %errorlevel% 為 0,否則為 1。
where $PATH:notepad.exe
→ 在 PATH 指定的路徑中搜尋 notepad.exe。
where C:\Windows:notepad.exe
→ 只在 C:\Windows 目錄中搜尋 notepad.exe。
PATHEXT 中的副檔名(如 .EXE, .BAT)。$ENV: 與 <Path>: 的語法 不可與 /r 同時使用。where /r D:\ *.cpp *.h
| File5 | File | Last Modified |
|---|---|---|
| Windows PowerShell Execution Policy | Windows PowerShell Execution Policy | 1:26 AM - December 07, 2025 |
| windows batch file with path name | windows batch file with path name | 1:26 AM - December 07, 2025 |
| Untitled | Untitled | 1:25 AM - December 07, 2025 |
| Everything極高速Windows 檔案搜尋工具 | Everything極高速Windows 檔案搜尋工具 | 1:25 AM - December 07, 2025 |
| Windows多種命令列工具搜尋檔案 | Windows多種命令列工具搜尋檔案 | 8:21 PM - December 06, 2025 |