![](/img/trans.png)
[英]How can I search all files in a directory for a list of strings(numbers)?
[英]How can I list and print files in a directory?
我正在嘗試此操作,但它不打印任何內容:
Dir -Recurse "C:\temp" | Select Fullname
看起來這個命令只是選擇文件名。 我想在控制台中看到它們。
Dir -Recurse c:\path\ | Get-Childitem
您的命令應該按原樣工作。 事實上,您已經在調用Get-ChildItem
。 如果您檢查Get-Alias
您將看到我想告訴您的內容。
PS C:\users\Cameron\Downloads> Get-Alias dir
CommandType Name ModuleName
----------- ---- ----------
Alias dir -> Get-ChildItem
您的代碼轉換為
Get-ChildItem -Recurse "C:\temp" | Select Fullname
同樣,我不確定為什么您的代碼不生成輸出,因為在包含文件或目錄的文件夾上這完全沒問題。 可能是位置參數的問題? 你的 PowerShell 版本是什么? (使用Get-Host
)。
您擁有的代碼會將所有文件路徑發送到控制台。 你想要其他地方的輸出嗎?
如果路徑中有文件夾,則可以肯定此代碼會將輸出加倍,因為目錄將輸出到第二個Get-ChildItem
Dir -Recurse c:\path\ | Get-Childitem
考慮以下文件夾樹
C:\TEMP\TEST
│ File1.txt
│ File2.txt
│
└───Folder1
File3.txt
考慮針對該文件夾樹運行的兩個命令。
PS C:\users\Cameron\Downloads> Dir -Recurse c:\temp\test | Select Fullname
FullName
--------
C:\temp\test\Folder1
C:\temp\test\File1.txt
C:\temp\test\File2.txt
C:\temp\test\Folder1\File3.txt
PS C:\users\Cameron\Downloads> Dir -Recurse c:\temp\test | Get-Childitem | Select Fullname
FullName
--------
C:\temp\test\Folder1\File3.txt
C:\temp\test\File1.txt
C:\temp\test\File2.txt
C:\temp\test\Folder1\File3.txt
第二個命令顯示了兩個名為File3.txt
文件,而實際上只有一個。
get-childitem | format-list > filename.txt
這將為您提供一個包含名稱、大小、最后修改時間等的文本文件。
如果您想要項目中的特定參數...例如文件名,只有命令是
get-childitem | format-list name > filename.txt
這是給你相同的文本文件,但只列出文件的名稱。
可能還值得一提的是查看隱藏物品所需的 -force 開關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.