$DesktopPath = [Environment]::GetFolderPath("Desktop")
$WorkPath = 'C:\...\AndroidProject\...\app\src\main\res'
$DownloadPath = "C:\Users\dever\Downloads"
$Info = Get-ChildItem -Path $DownloadPath *.zip | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1
$ZipPath = $Info.FullName
Expand-Archive $ZipPath -DestinationPath $DesktopPath
$MinmapFolder = Get-ChildItem -Path $DesktopPath mipmap-*
foreach ($FolderPath in $MinmapFolder)
{
$NewFolderName = $FolderPath -replace "mipmap", "drawable"
Rename-Item -Path $DesktopPath\$FolderPath -NewName $DesktopPath\$NewFolderName
}
function GetImageName
{
$InputName = Read-Host '图片名称: '
$WebpName = $InputName + '.webp'
return $WebpName
}
$InputKey = $null
$IsExists = $null
function NameIsExists ($ImageName)
{
$WorkRes = Get-ChildItem -Path $WorkPath\drawable-*
foreach ($DrawablePath in $WorkRes)
{
Set-Variable "IsExists" (Test-Path "$DrawablePath\$ImageName") -Scope 2
if ($IsExists)
{
Write-Output "IsExists: $IsExists"
$TempInput = Read-Host '存在同名文件, 是否覆盖? Y(覆盖)/N(退出)/R(重命名)'
Set-Variable "InputKey" $TempInput -Scope 2
break
}
Set-Variable "InputKey" $null
}
}
function RenameFileAndCopy ($ImageName)
{
Get-ChildItem -Path $DesktopPath\drawable-*\*.webp -Recurse | ForEach { Rename-Item -Path $_ -NewName $ImageName }
Copy-Item -Path $DesktopPath\drawable-* -Recurse -Destination $WorkPath -Force
}
function Check {
$ImageName = GetImageName
NameIsExists $ImageName
Switch ($InputKey)
{
'Y'
{
RenameFileAndCopy (Get-Variable "ImageName" -ValueOnly)
}
'R'
{
Set-Variable "InputKey" $null
check
}
'N'
{
Remove-Item -Path $DesktopPath\drawable-* -Recurse
Exit
}
''
{
if (Get-Variable "IsExists" -ValueOnly)
{
Set-Variable "InputKey" $null
check
}
else
{
renameFileAndCopy (Get-Variable "ImageName" -ValueOnly)
}
}
}
}
Check
Remove-Item -Path $DesktopPath\drawable-* -Recurse