![](/img/trans.png)
[英]How do you match an exact file extension under Windows/command line/file open dialog?
[英]Windows command line search for exact extension with dir
當我進行搜索時:
dir /b /s *.txt
我得到所有擴展名為.txt
的文件/文件夾。 但是當它們有像.txtx
這樣的擴展名時,我也會得到它們。 如何搜索確切的擴展名?
你可以試試這個
dir /s /b *.txt | findstr /v .txt.
要么
dir /s /b *.txt | findstr /e .txt
要么
dir /b *.txt | findstr .txt$
我無法弄清楚為什么它會像這樣,但這有效: dir /b /s .txt | findstr /e .txt
dir /b /s .txt | findstr /e .txt
。 丑陋但有效。
dir C:\XML /s /b | findstr /e.xml > C:\XML\list.txt
這對我有用,只需將 .xml 擴展名更改為 .txt
拆分命令以便更好地理解:
dir /s /b
^ ^
| |
| Displays a **bare** list of directories and files, with no additional information.
|
~ Lists every occurrence of the specified file name within the
specified directory and all **subdirectories**.
findstr /e
^
|
Matches the text pattern if it is at the **end** of a line.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.