我需要编写一个脚本来将 zip 文件解压缩到唯一的文件夹中并在其中执行一个 bat 文件。
我可以使用以下代码完成解压缩过程。我在执行 bat 文件时遇到问题。我需要以一种能够对其当前所在文件夹的文件执行操作的方式执行 bat 文件。
bat文件包含此代码
copy *.prn /b \\PC\Printer
我当前的 Powershell 脚本
$shell=new-object -com shell.application
$CurrentLocation=get-location
$CurrentPath=$CurrentLocation.path
$Location=$shell.namespace($CurrentPath)
# Find all the Zip files and Count them
$ZipFiles = get-childitem *.zip
$ZipFiles.count | out-default
# Set the Index for unique folders
$Index = 1
# For every zip file in the folder
foreach ($ZipFile in $ZipFiles)
{
# Get the full path to the zip file
$ZipFile.fullname | out-default
# Set the location and create a new folder to unzip the files into - Edit the line below to change the location to save files to
$NewLocation = "E:\BCode\$Index"
$A = "E:\BCode\$Index"
New-Item $NewLocation -type Directory
# Move the zip file to the new folder so that you know which was the original file (can be changed to Copy-Item if needed)
Move-Item $ZipFile.fullname $NewLocation
# List up all of the zip files in the new folder
$NewZipFile = get-childitem $NewLocation *.zip
# Get the COMObjects required for the unzip process
$NewLocation = $shell.namespace($NewLocation)
$ZipFolder = $shell.namespace($NewZipFile.fullname)
# Copy the files to the new Folder
$NewLocation.copyhere($ZipFolder.items())
#NOT WORKING
#ITS NOT SENDING FILES TO THE PRINTER
#PRINTER NAME & PC NAME ARE PREFECT
$PC = "$A\*.prn" + ' /b //Samsung-2012/Zebra'
cmd \c COPY $PC
# Increase the Index to ensure that unique folders are made
$Index = $Index + 1
}
$destination = 'E:\BCode'
Get-ChildItem -Path $Destination -Recurse | Remove-Item -force -recurse