如何使用PowerShell创建一个目录并进入目录读取文件

2025年03月21日 23:16
有2个网友回答
网友(1):

New-Item 用于创建文件和文件夹.
New-Item xxxx -type directory
新建的目录是没有文件的。

进入目录是
cd xxx
或者Set-Location xxxx

网友(2):


# 桌面路径 
$desktop = [System.Environment]::GetFolderPath('Desktop')
$path = Join-Path $desktop -ChildPath 'newFolder'

# 创建目录 
if (-not (Test-Path $path))
{
New-Item $path -ItemType "directory"
}

# 列出文件
Get-ChildItem $path -Filter "*.txt" -File