简体   繁体   English

如何使用 Powershell 在没有 Mode、LastWrite 等的情况下导出 CSV 文件中的目录文件?

[英]How to export directory files in CSV file without Mode, LastWrite etc using Powershell?

Using dir > list.csv will create the list I need in whichever directory im in, but it includes unnecessary information as well.使用dir > list.csv将在我所在的任何目录中创建我需要的列表,但它也包含不必要的信息。 It has a column for the Mode, LastWriteTime, LengthName etc which I then have to manually delete, because I'm using OpenOffice and need the list of files to compose a new CSV which I'm then going to import into a database.它有一列用于 Mode、LastWriteTime、LengthName 等,然后我必须手动删除这些列,因为我使用的是 OpenOffice,并且需要文件列表来组成一个新的 CSV,然后我将其导入数据库。

I would like to use a switch that allow me to solely export the file name in CSV not the other items.我想使用一个开关,允许我仅导出 CSV 中的文件名而不是其他项目。 Is this possible with a useful command or switch or would it involve scripting?这是否可以通过有用的命令或开关实现,还是涉及脚本?

Do you mean this?你是这个意思吗?

Get-ChildItem | Select-Object -ExpandProperty Name > list.txt

The list.txt will contain the filename of each file. list.txt将包含每个文件的文件名。

(Note that CSV means "comma-separated values" and is a delimited file format. A plain list of names really isn't a CSV file.) (请注意,CSV 的意思是“逗号分隔值”并且是一种分隔文件格式。简单的名称列表实际上不是 CSV 文件。)

Try this:尝试这个:

Get-ChildItem | Select-Object -ExpandProperty Name > test.csv 
(Get-Content test.csv) -join ',' | Set-Content test.csv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM