$tarName = "SCompiler.tar" # 切换到脚本所在目录的上一级目录(假设作为项目根目录) $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition $projectRoot = Split-Path -Parent $scriptDir Set-Location $projectRoot Write-Output "当前工作目录:$(Get-Location)" # 如果旧的 tar 包存在,先删除 if (Test-Path $tarName) { Write-Output "发现旧的 $tarName,正在删除..." Remove-Item $tarName } # 创建新的 tar 包并排除某些文件和目录 Write-Output "正在创建新的 $tarName ..." $excludeOptions = @( "--exclude=$tarName" "--exclude=build_project2tar.ps1" "--exclude=.git" "--exclude=.idea" "--exclude=.run" "--exclude=target" "--exclude=.gitignore" ) # 调用 tar 命令 & tar -cf $tarName $excludeOptions * # 验证结果 if (Test-Path $tarName) { Write-Output "✅ 成功创建 $tarName" } else { Write-Output "❌ 创建失败,请检查 tar 命令或排除项" }