标题: [问题求助] bat的代码能转成ps1么 [打印本页]
作者: sykIII 时间: 2019-11-11 13:08 标题: bat的代码能转成ps1么
bat限制太多了,想试试powershell- @echo off
- :loop
- if "%~1"=="" goto :done
- if not exist "%~1\*.ico" goto :err
- del "%~1\desktop.ini" /f /q /ah 1>nul 2>nul
- set "dir=%~1"
- pushd "%dir%"
- for /f "delims=" %%a in ('dir /a-d/b *.ico') do set "icon=%%~nxa"
- (echo [.ShellClassInfo]
- echo IconResource=%icon%
- echo [ViewState]
- echo Mode=
- echo Vid=
- echo FolderType=Pictures
- )>"%dir%\desktop.ini"
- attrib +s +h "%dir%\desktop.ini"
- attrib +s +h "%icon%"
- attrib +r /d "%dir%"
- popd
- goto :next
- :err
- echo;找不到文件 - %~nx1
- :next
- shift
- goto :loop
- :done
- echo;
- pause
复制代码
作者: ivor 时间: 2019-11-11 16:45
本帖最后由 ivor 于 2019-11-11 16:55 编辑
- function err {
- param (
- [string]$file
- )
- "找不到文件 - {0}" -f $file
- }
-
- foreach ($arg in $args) {
- if (![System.IO.File]::Exists($arg.ToString()+"\*.ico")) {
- err(([System.IO.FileInfo]$arg.ToString()).Name)
- continue
- }
- Remove-Item $arg+"\desktop.ini" -Force
- $dir = $arg
- Push-Location $arg
- foreach ($item in (Get-ChildItem -File *.ico)) {
- $icon = $item.Name
- }
- '[.ShellClassInfo]
- IconResource={0}
- [ViewState]
- Mode=
- Vid=
- FolderType=Pictures
- ' -f $icon | Out-File -FilePath $dir+"\desktop.ini"
- attrib +s +h $dir+"\desktop.ini"
- attrib +s +h "%icon%"
- attrib +r /d $dir
- Pop-Location
- }
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |