我有以下的函数,可以将文件转换为Base64。
如果用户没有输入文件路径,如何使该函数接受默认值呢?
提示:请勿修改HTML标签。
B64 -f $filePath
提示:请勿修改HTML标签。
function B64{
param (
[Parameter (Mandatory = $True, ValueFromPipeline = $True)]
[Alias("file")]
$f
)
$File = "\converted.txt"
$FilePath = ([Environment]::GetFolderPath("Desktop")+$File)
$Content = Get-Content -Path $f
$converted = [convert]::ToBase64String([System.Text.encoding]::Unicode.GetBytes($Content))
$numChar = $converted.length
$incriment = 275
$pre = "STRING powershell -enc "
$string = "STRING "
function splitLines{
While ($converted)
{
$x,$converted = ([char[]]$converted).where({$_},'Split',$incriment)
$x -join ''
}
}