Директории в PowerShell

Содержание
Введение
Test-Path: проверить существование
New-Item: Создать директорию
Expand-Archive: распаковать архив
Rename-Item: переименовать директорию
Join-Path объединение путей
Похожие статьи

Проверить существование директории

Проверить есть ли в текущей директории поддиректория swagger-ui

${SwaggerPath} = Join-Path ${pwd} "swagger-ui"; If (Test-Path -path ${SwaggerPath}) { Write-Host "swagger-ui dir exists" -f Green } Else { Write-Host "swagger-ui dir does not exist" -f Yellow }

Проверить и если такой директории нет - скачать архив

$SWAGGER_URL = "https://github.com/swagger-api/swagger-ui/archive/refs/tags/v5.11.10.zip"; ${SwaggerPath} = Join-Path ${pwd} "swagger-ui"; If (Test-Path -path ${SwaggerPath}) { Write-Host "swagger-ui dir exists" -f Green } Else { Write-Host "swagger-ui dir does not exist - starting download" -f Yellow Invoke-WebRequest $SWAGGER_URL -OutFile swagger-ui.zip }

Создать директорию

Для создания новой директории используется команда New-Item с ItemType directory

New-Item -Path "c:\" -Name "logfiles" -ItemType "directory"

Проверить наличие директории. Если её нет - создать.

If (Test-Path -path "test\mod\etc\") { Write-Host "test\mod\etc\ dir exists" -f Green } Else { Write-Host "test\mod\etc\ dir does not exist - creating" -f Yellow New-Item -Path "test\mod\" -Name "etc" -ItemType "directory" }

Распаковать архив

Распаковать архив в текущую директорию

Expand-Archive -Path swagger-ui.zip -DestinationPath .

Переименовать директорию

Rename-Item -Path swagger-ui-5.11.10 -NewName swagger-ui

Banner image

Join-Path

Объединить пути можно следующим образом

$TMP_PATH = "C:/tmp_python" $TMP_PYTHON_EXE = Join-Path -Path $TMP_PATH -ChildPath "python.exe"

Article author: Andrei Olegovich

Похожие статьи
Windows
PowerShell
Install
Basics
Alias
Functions
Network
Users
Files
REST API requests
Errors

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: