简体   繁体   English

如何将文件夹中的所有文件输出到一个文件

[英]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.

相关问题 将与模式匹配的行从文件夹中的所有文本文件提取到单个输出文件 - Extract lines matching a pattern from all text files in a folder to a single output file 递归计算文件夹中的文件并输出到文件 - recursively count files in folder and output to file 如何使用 powershell 将一个 window 文件夹中的所有文件重命名为另一个文件夹中每个文件的名称? - how to rename all files in one window folder to names of each file in another folder using powershell? 如何使用 PowerShell 搜索特定文件名然后将该文件之后的所有文件移动到另一个文件夹 - How to search for a specific file name then move all files after that file to another folder using PowerShell zip 一个文件夹下的所有文件如何单独显示? - How to zip all the files in a folder individually? 如何解压缩文件夹中的所有文件? (不是.zip扩展名) - How to unzip all files in folder? (Not .zip extension) 如何获取特定文件夹中的所有文件? - How to get all the files in a specific folder? 如何在 powershell output 中打印文件夹和文件名 - How to print folder and file names in powershell output 如何查找文件夹中文件名末尾没有特定字符的所有文件? - How to find all files in a folder which do not have a specific character in the ending of their file names? 如何使用Powershell获取文件夹中所有文件夹名称而不是子文件夹中文件/子文件夹的.txt文件? - How to get a .txt file of all folders names inside a folder but not the files/subfolders inside the child folders using powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM