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

2025-03-21 23:16:11
推荐回答(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