Power Shell
Code:
$Path = "C:\Users\xxxx\Downloads\New";
$filename="$Path\c.txt";
#create file if it does not exist
if(-not (Test-Path $filename))
{
New-Item -ItemType file -Path $filename
}
#write current date to file
$currentDate = get-date
Add-Content $filename -Value $currentDate
#get files in the folder and assign items to a collection
$files = Get-ChildItem -Path $Path
#iterate item
foreach($item in $files){
Write-Host $item
}
output:
a.txt
b.txt
c.txt
#another output
$files | ForEach-Object -Process {$_.FullName}
Output:
C:\Users\xxx\Downloads\New\a.txt
C:\Users\xxx\Downloads\New\b.txt
C:\Users\xxx\Downloads\New\c.txt
#get window service
Get-Service * | Sort-Object ServiceType | Format-Table Name, ServiceType, Status -AutoSize
Output:
Name ServiceType Status
---- ----------- ------
AdobeARMservice Win32OwnProcess Running
MSOLAP$SQLSERVER2012 Win32OwnProcess Running
MSOLAP$BERNIE_SQLSERVER Win32OwnProcess Running
#switch
switch(4,2)
{
4{"4"}
3{"3"}
2{"2"}
1{"1"}
}
Output:
4
2
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?