我需要编写一个脚本来将zip文件解压缩到唯一的文件夹中并在其中执行bat文件。
我可以使用以下代码完成解压缩过程。 我在执行bat文件时遇到问题。我需要以能够对当前文件夹的文件执行操作的方式执行bat文件。
bat文件包含此代码
copy *.prn /b \\PC\Printer
My Current Powershell Script
$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
答案 0 :(得分:0)
为什么不在powershell脚本中嵌入批处理文件中的一行,然后可以使用powershell脚本中的变量。
只需将cmd / c放在副本之前:
cmd /c copy "$NewLocation\*.prn" /b \\PC\Printer