[英]How to output all files in a folder to a file
I have a question about powershell.我有一个关于powershell的问题。
How would i output all filenames from all the files in a folder (not the extension, only the filename of the files) to a texfile listing each name with a space on each line will be a list of names in the textfile?我如何将文件夹中所有文件的所有文件名(不是扩展名,只有文件的文件名)输出到一个 texfile 列出每个名称,每行一个空格将是文本文件中的名称列表?
Example, in the folder these files exist.
text1.txt text2.txt text3.txt
in the textfile i want to list them as this when they are put in there.
text1
text2
text3
I would try something like this:我会尝试这样的事情:
$path = "your path"
Get-ChildItem $path -recurse | ForEach-Object { $_.BaseName } | Out-File .\output.txt
Which first extracts all files recursively with GetChildItem
, then redirect with Out-File
the BaseName
of each file to output.txt
.首先使用
GetChildItem
递归提取所有文件,然后使用Out-File
将每个文件的BaseName
重定向到output.txt
。
If you don't want to recurse all children inside the folder, remove -recurse
.如果您不想递归文件夹内的所有子项,请删除
-recurse
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.